我的一个对话框有一个非自定义标题:
名称对话框.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>
这是它的样子:
我的一个对话框有一个带有演员图标的自定义标题。 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();
}
}
player_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>
player_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>
这是它的样子:
我只希望两个对话框具有一致的格式。