0

One of my dialogs has a non-custom title:

NameDialog.java

public class NameDialog extends DialogFragment {
    @Override
    @NonNull
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();
        return builder.setTitle(R.string.name)
                .setView(inflater.inflate(R.layout.name_dialog, null))
                .setPositiveButton(R.string.next, null)
                .create();
    }
}

name_dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">

    <EditText
        android:id="@+id/name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
</LinearLayout>

This is what it looks like: NameDialog

One of my dialogs has a custom title with the cast icon. PlayersDialog.java

public class PlayersDialog extends DialogFragment {
    @Override
    @NonNull
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();
        return builder
                .setCustomTitle(inflater.inflate(R.layout.players_title_dialog, null))
                .setView(inflater.inflate(R.layout.players_dialog, null))
                .setPositiveButton(R.string.start_game, null)
                .create();
    }
}

players_dialog.xml

<RelativeLayout xmlns: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"
                tools:context=".PlayersDialog">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:textAppearance="?android:attr/textAppearanceLarge"/>

    <ListView
        android:id="@+id/players"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="false"/>

</RelativeLayout>

players_title_dialog.xml

<RelativeLayout xmlns: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:orientation="horizontal"
              tools:context=".PlayersDialog">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/title"
        android:text="@string/players"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_marginLeft="5dp"/>

    <android.support.v7.app.MediaRouteButton
        android:id="@+id/media_route_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_centerVertical="true"
        android:mediaRouteTypes="user"
        android:visibility="gone"/>

</RelativeLayout>

This is what it looks like: PlayersDialog

I just want both dialogs to have consistent formatting.

1 Answers1

0

In your players_title_dialog.xml file replace the players textView with the following

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/title"
        android:text="@string/players"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#3db6e3"
        android:layout_marginLeft="10dp"/>

And may be the font size could be decreased by 1dp and padding could be added 3px in you list

Mohammad Arman
  • 6,730
  • 2
  • 34
  • 48
  • Is there a way to reference the color and margin so it isn't hard coded? – AlanRosenthal Mar 18 '15 at 16:49
  • Actually, there isn't any reference as android source is open for all, any one can easily find the specifications and reuse it. From android source you can also see the font/margin etc of the default alertDialog. then you can create your own in custom and reuse it. Here you can find the default AlertDialog specification: http://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog – Mohammad Arman Mar 18 '15 at 16:57
  • Where did you find the value "3db6e3"? – AlanRosenthal Mar 18 '15 at 17:24
  • i just picked that from the Title color of default alertDialog using color picker. Nothing official here. – Mohammad Arman Mar 18 '15 at 17:38