Skip to content Skip to sidebar Skip to footer

Android: How To Customize Alertdialog, Dialog An Spinner Titles

I want to customize all dialogs, alertDialogs and spinner. I want to change the color of text and the background of the title bar. I try to explain better: I want the text (JOLLY

Solution 1:

Ok, I've almost solved the problem (I'm answering my own question because it may help others with the same problem as mine). The problem remains for spinners, DatePickers etc.

For the AlertDialogs I do something like this:

AlertDialog.Builderbuilder=newAlertDialog.Builder(MyActivity.this, AlertDialog.THEME_HOLO_LIGHT);
//Then I do what I need with the builder (except for setTitle();LayoutInflaterinflater= getLayoutInflater();
View view=inflater.inflate(R.layout.dialog_custom_title, null);
TextViewtitle= (TextView)view.findViewById(R.id.myTitle);
title.setText("Title I want to show");
builder.setCustomTitle(view);
AlertDialogalert= builder.create();
alert.show();

dialog_custom_titile.xml :

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#044592" ><TextViewxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/myTitle"android:layout_width="fill_parent"android:textSize="20dp"android:layout_height="70dp"android:layout_marginLeft="25dp"android:paddingTop="22dp"android:textColor="@android:color/white"android:textStyle="bold" /></RelativeLayout>

for the Activities that I want to look like Dialogs I do like this: I declare them in the Manifest.xml as follows:

<activityandroid:name="com.aveschini.AnotherActivity"android:screenOrientation="portrait"android:label="My Dialog"android:theme="@style/MyDialog"android:windowSoftInputMode="adjustPan" />

then, in the res/values/styles.xml file I do like this:

<stylename="AppTheme"parent="android:Theme.Holo.Light" /><stylename="MyDialog"parent="android:Theme.Holo.Light.Dialog"><itemname="android:windowTitleStyle">@style/DialogWindowTitle</item></style><stylename="DialogWindowTitle"><itemname="android:textAppearance">@style/TextAppearance.DialogWindowTitle</item><itemname="android:background">#044592</item></style><stylename="TextAppearance.DialogWindowTitle"parent="android:TextAppearance"><itemname="android:textColor">@android:color/white</item><itemname="android:textStyle">bold</item><itemname="android:textSize">20sp</item></style>

I still get the light blue divider between the title and the body... still working on it. As already said, I still don't know how to deal with Spinners, DatePicker, etc...

That's the result: AlertDialog:

enter image description here

And an Activity with the look of a dialog:

enter image description here

Post a Comment for "Android: How To Customize Alertdialog, Dialog An Spinner Titles"