I am trying to set a custom title on my activity (using requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);), with a custom title height. I have my custom style and theme all set up. Everything works fine as long as my theme inherits from android:Theme. It gets the custom background, custom titlebar height, all as expected. However, if my custom theme inherits from android:Theme.Dialog then it refuses to honor my custom titlebar height. It is just stuck at about 25px or so. (Which is weird, since before putting in any custom title stuff, the default titlebar was about 50px or so).
Is there any way to set a custom title on a Dialog?
Why don't u create custom dialog instead.
Hope this can help
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.maindialog);//this will get the custom dialgo layout
dialog.setTitle("Here is your custom title");
dialog.setCancelable(true);
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
//custom dialog has been created. Time to show
dialog.show()
Related
I show a DialogFragment from another DialogFragment. I need to set title and a button just next to it. I don't want to reimplement the theme and create a custom view inside DialogFragment's content view instead of dialog title (because it's error-prone and time wasting). Is it even possible? I tried many API functions, AlertBuilder, ActionBar, this and that, still didn't found anything that fits my needs.
Try something like this:
// Title
final int titleId = getResources().getIdentifier("alertTitle","id","android");
TextView title = (TextView) popup.findViewById(titleId);
title.setText("My new title");
// Title's parent layout
ViewGroup viewGroup = (ViewGroup) title.getRootView();
// Button
Button button = new Button(this);
button.setText("A Button");
viewGroup.addView(button);
Note: You may need to adjust the button and title objects' LayoutParams.
An update. This can be achieved by calling setCustomTitle on AlertDialog.Builder class. Available since api level 1, and do not require a bunch of code.
Example:
AlertDialog.Builder(getActivity()).setCustomTitle(getActivity().getLayoutInflater().inflate(R.layout.my_custom_view, viewGroup)).create()
I'm looking at the documentation here:
http://developer.android.com/guide/topics/ui/dialogs.html#PassingEvents
And all their examples seem to overlook the developer's potential desire to totally alter the appearance and/or positioning of the OK | Cancel buttons.
I feel like the solution with the DialogFragment comes close, but still there's no obvious way for me to define what View in my activity should BE the OK button, so that I can easily attach the callback to it.
What am I missing? Or is it really not possible to manipulate the appearance and position of the buttons in anything that extends AlertDialog or DialogFragment?
You can use Dialog and add your own custom layout to it and control the appearance of every view in it. Here is an example how you can do this :
final Dialog alert = new Dialog(FingerPaintActivity.this, android.R.style.Theme_Light_Panel);
alert.requestWindowFeature(Window.FEATURE_NO_TITLE); // no title
alert.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation; // this is used for custom animation when dialog is showing and hiding
alert.setContentView(getLayoutInflater().inflate(R.layout.stamps, null)); // here is your custom layout
alert.getWindow().setLayout(width-50, (height-100)); // set height / width
and you can use set listeners to your views (for example a button) like this :
Button myOkBtn = (Button) alert.findViewById(R.id.myOkBtn);
myOkBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
I have a Dialog with a custom layout (very simple). I set it up using the code below:
public static Dialog createGPSDialog(final Activity activity, boolean isLocationEnabled) {
final Dialog dialog = new Dialog(activity, R.style.Theme_Sherlock_Light_Dialog);
LinearLayout contentView = (LinearLayout) activity.getLayoutInflater().inflate(R.layout.dialog_twobutton, null);
dialog.setContentView(contentView);
return dialog;
}
There's some code I omitted, but it isn't relevant. Anyway, this is how it looks in gingerbread:
and this is how it looks on jellybean (probably ics as well):
The title area for the dialog is kept on JB, even after setting ContentView. Is there a workaround for this?
If you want to be completely custom and get rid of the title bar, try adding this line to your code:
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
The key is defining a theme for your dialog. The constructor for Dialog takes a theme resources id. Just use one of android's android.R.theme.xxx.
When using the AlertDialog.Builder you can define a new theme using the contextthemewrapper.
http://developer.android.com/reference/android/view/ContextThemeWrapper.html
I want to create context menu as follows , i am sure this is not traditional the context menu , its a kind of alert dialog which is being customized.
I tried following code but it adds the footer end of the ListView not to the dialog / context menu reference thread is ContextMenu with footer view (to add checkbox for 'make default' option)
dialog2.getListView().addFooterView(new CheckBox(this))
I have gone through the followig tutorial which has custom context menu , is it possible
to use this code to set a footer
http://www.tanisoft.net/search/label/Tutorial
I want following features , preciously the checkbox in the footer
EDIT
I reached to this part now there are only two issues
1) Dialog Title Icon
2) Dialog Bottom Blue Color ( which is a default
color of android )
and i don;t know how to achieve above two task
Here is my code to create dialog
contactDlg = new Dialog(this);
contactDlg.requestWindowFeature( Window.FEATURE_LEFT_ICON );
contactDlg.setTitle(contactStore.getContactName());
contactDlg.setContentView(R.layout.contact_dialog);
contactDlg.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.bottom_bar);
contactAdapter = new ContactAdapter(this,contactStore.getContactNumber());
modeList = (ListView) contactDlg.findViewById(R.id.contactDlgList);
modeList.setBackgroundResource(android.R.color.white);
modeList.setCacheColorHint(Color.WHITE);
modeList.setAdapter(contactAdapter);
contactDlg.show();
No need to do any thing special for this.This can be achieved easily by creating your own layout containg the list shown in this pic and the footer view in the dialog itself with thye color and style you want.Then just make the property of the dialog named "windowFrame" to be null by < item name="android:windowFrame">#null< / item>Also you can make a separate "theme.xml" in the "values" folder and define this and similar kinda properties in that file.In code, when you instantiate the dialog object, set this theme to it.The basic purpose of doing this is to achieve the total control on what to show and what not in the dialog you create.
I have a dialog with a custom theme:
final Dialog d = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
This makes my dialog background transparent.
Now the problem is if I let the normal theme(style.dialog) it is centered in my screen but now it has no layout and is in the upper left corner of my screen. Is there a way to programmatically center the dialog?
I didn't actually find a programatic solution to my problem, instead in my customdialog.xml I put the main layout into a RelativeLayout with fill_parent for height/width and then put the layout atribute centerInParent="true".
construct your dialog by extends Dialog,
override the style & content(by setContentView)