I have created a custom dialog box extending the DialogFragment class. As stated in the Androïd developer's guide, I have set the style and theme of my dialog. I use the DialogFragment.STYLE_NORMAL style, which, I suppose, authorizes to set a title to the box. This seems confirmed by the fact that a style called DialogFragment.STYLE_NO_TITLE exists.
The problem is I can't find any function to set this title.
How can I do?
Thanks in advance for the time you will spend trying to help me.
Just call getDialog().setTitle("My Dialog Title") to set the title
I think you could call getDialog() to get the contained Dialog instance, then call setTitle on that with the required title.
A bit of a guess, since I'm not an Android developer.
Related
Working with libGDX, and in this particular project we are using Dialog to have a box popup when the user clicks a certain button.
What I want is to be able to dismiss the Dialog by clicking outside of it.
At other times, I have used two tables, a background table and a menu table, and added a transparent background to the background table that when clicked will remove both of those tables from the Stage.
I have tried making a class that has a both a Dialog and a background table like the one mentioned above, but the background table never receives any actions.
I have also tried simply adding this background table to the stage before creating the dialog box, but this does not work either.
Finally, I have also tried to subclass Dialog, the idea being to override the show(stage) method to change its behavior, but I don't know how to do this one, and I'm not sure if it would work, anyway.
I believe the problem is that dialog.show(stage) changes the situation in the stage to only accept clicks inside the Window of the dialog box. I have seen this question about adding a close button to a dialog box, but playing with the clipping settings is not working to fix this problem.
There is also the possibility that when show() calls the pack() method and does its layout thing that something is happening that is making what I am trying to do impossible. I think that the solution will be overriding show() or overriding pack(), or both, but I don't know how to do this.
I can post code if need be, but this should be a pretty complete description of what I have tried and what I need to accomplish.
I know this is an old question but for those like me that searched the entire web for an answer only to find it inside libGDX code, the answer to .close() a libGDX dialog by code is simply to call the method
dialog.hide();
EDIT (added from the comments below):
so all he needs to do is register a global touch down event and see if
the touch has happened inside the Rectangle of his dialog, if not,
close it
In my android app, I want to make a dialog box, the kind of one you get from alertbuilders, where you get access to set positive/neutral/negative button click, but I also want to use the .setcustomview() to load the content with my xml file.
Does android have a way to do this? I want to avoid making those buttons...
Thanks
I don't see a setcustomview() method for the AlertDialog.Builder class, but I do see a setView() method, if that's what you mean. :)
From my experience, using setView() will allow you to set your custom XML layout (though you will still need to inflate it first) without requiring you to recreate / add buttons to your layout. You just need to call the setXxxButton() methods before you build.
i would like to ask a question with regards to AlertDialogs which i would like to use in GoogleMaps V2. I read about the custom InfoWindow documentation from the android developers and noticed that they advised not to put any interaction widgets (Buttons, Textbox etc etc) onto an OnClick function. Now, i would like to know if i could use a default alert dialog and put it into an OnClick function for the custom InfoWindow. Is it possible?
Yes that should work fine. The reason why you should not (and cannot, really) put interactive elements in an InfoWindow is because the InfoWinow is statically rendered when shown, making any interactive elements you place in it effectively useless.
I'm currently implementing theme support for my application and a part of it is changing the action bar app icon. I want to use a dark icon when Holo Light is selected. Everything is done in the method except for the part where the action bar app icon is set. The code that I'm trying to use is:
getActionBar();
ActionBar.setIcon(R.drawable.my_icon);
"There is no such reference available here" is the error that I'm getting. How should this be done correctly?
BTW my minSdkVersion is 14 so no action bar Sherlock stuff.
getActionBar();
You're throwing the action bar away right there. getActionBar() returns an instance of ActionBar, which you then need to call setIcon() on. Like so:
ActionBar actionBar = getActionBar();
actionBar.setIcon(R.drawable.my_icon);
Though its a bit late answer but i thought it might be useful.
From inside an activity:
For API level 14 or higher:
getActionBar().setIcon(R.drawable.my_icon);
For lower API level we have to extend ActionBarActivity and then:
getSupportActionBar().setIcon(R.drawable.my_icon);
From inside a Fragment:
For API level 14 or higher:
getActivity().getActionBar().setIcon(R.drawable.my_icon);
For lower API level we can use (activity must extend ActionBarActivity):
((ActionBarActivity)getActivity()).getSupportActionBar().setIcon(R.drawable.my_icon);
And in both cases we have to call setDisplayShowHomeEnabled(true) before setting the icon or logo.
((ActionBarActivity)getActivity()).getSupportActionBar().setDisplayShowHomeEnabled(true);
((ActionBarActivity)getActivity()).getSupportActionBar().setIcon(R.drawable.my_icon);
I am using this for my use , and it's working for me. Hope this help all
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.icon);
You need to add the drawable that you want to reference into your drawable/ folder under res/.
edit: In your Android installation folder there are a lot of stock images to use. You can probably find it there.
The existing answer is very correct. There is, however, also an alternative.
A minimal approach would be to use
getActionBar().setIcon(R.drawable.my_icon);
Gets your job done right away. :)
Technical Details: Since getActionBar() by default returns an object, you can directly manipulate it without having to receive it in an in-scope object explicitly.
Calling to setIcon wasn't enough for me.
Before that, I had to switch the display from activity logo to activity icon:
actionBar.setDisplayUseLogoEnabled(false);
For the differences between activity icon and logo see Android icon vs logo.
Try this
setSupportActionBar(toolbar);
if (getSupportActionBar() != null)
getSupportActionBar().setIcon(R.drawable.your_icon);
Kotlin answer:
In your activity just paste this code.
You need to enable the option first:
supportActionBar?.setDisplayShowHomeEnabled(true)
supportActionBar?.setIcon(R.drawable.your_icon)
What I want to do is quite simple : to display a dialog form containing an EditText in which the user can specify a message.
So far, I have tried to use the DialogFragmentclass. With the explanations found in the developer's guide, I have been able to display an alert dialog box showing a message. But I can't figure out how neither to change the layout of the AlertDialog created to use an XML file of my own or to replace the AlertDialog with a customized class extending the View class for instance.
Am I missing something? Or am I completely on the wrong way?
Thanks in advance for the time you will spend trying to help me.
You absolutely can do this, even using an AlertDialog!
You just have to set a custom layout for the dialog, in AlertDialog you would use the setView method and if you want to use a more generic dialog you can use the setContentView method.
You can take a look at http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog for some more information and an example.
The example in the link provided is contrived without question but it is meant as a stepping stone towards a goal similar to what you are trying to accomplish.
There is a similar question/answer that might be of use to you.