android - 将样式应用于所有对话框(微调对话框、警报对话框等)

标签 android coding-style dialog themes

如何在不创建各种对话框窗口的自定义实现的情况下将样式应用于所有对话框?

我想覆盖 Theme.Dialog

我的最终目标是更改应用程序中每个弹出窗口的标题栏颜色。

最佳答案

请按照完整的教程 http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView
        android:src="@drawable/header_logo"
        android:layout_width="match_parent"
        android:layout_height="64dp"
        android:scaleType="center"
        android:background="#FFFFBB33"
        android:contentDescription="@string/app_name" />
    <EditText
        android:id="@+id/username"
        android:inputType="textEmailAddress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginBottom="4dp"
        android:hint="@string/username" />
    <EditText
        android:id="@+id/password"
        android:inputType="textPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginBottom="16dp"
        android:fontFamily="sans-serif"
        android:hint="@string/password"/>
</LinearLayout>


@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(inflater.inflate(R.layout.dialog_signin, null))
    // Add action buttons
           .setPositiveButton(R.string.signin, new DialogInterface.OnClickListener() {
               @Override
               public void onClick(DialogInterface dialog, int id) {
                   // sign in the user ...
               }
           })
           .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   LoginDialogFragment.this.getDialog().cancel();
               }
           });      
    return builder.create();
}

关于android - 将样式应用于所有对话框(微调对话框、警报对话框等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4089972/

相关文章:

java - 如何发送带有 HTML 标签的短信?

android - 如何用 Fab 打开 NavigationDrawer?

java - 从 C++/C# 到 Java——使用 "one public type per class"规则正确构建代码

android - 如何将数据从 Activity 发送到 AlertDialog 以显示它们

Android 在平板电脑中获取日历事件

Android OpenGL ES2.0 纹理交换

java - 从 CheckStyle 生成编码指南

c# - 你应该在 C# 中使用指针(不安全代码)吗?

安卓生命周期 : Fill in data in activity in onStart() or onResume()?

php - 删除确认 JavaScript