android - 覆盖 Android 中的对话框标题布局

标签 android layout dialog styles themes

我在我的 Android 应用程序中为对话框创建了一个自定义主题,我打算覆盖用于对话框标题的布局。我看到在标准的 android Theme 中有一个看起来像要修改的属性。

<item name="dialogTitleDecorLayout">@layout/dialog_title</item>

但是当我尝试在我的Theme

中覆盖它时
<style name="Theme.Dialog.MyDialog" parent="android:Theme.Dialog">
    <item name="android:windowBackground">@android:color/black</item>
    <item name="android:dialogTitleDecorLayout">@layout/my_dialog_title</item>
</style>

我看到以下错误:

No resource found that matches the given name: attr 'android:dialogTitleDecorLayout'

为什么我不能改变它,我怎么知道哪些属性可以改变,哪些不可以?

最佳答案

不可能像这样覆盖该项目。您必须使用所需的布局自定义对话框,然后在布局中您必须根据您的要求在此处应用主题。

dialog_title.xml

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/text" 
    android:text="@string/tell_a_friend"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="8dip"
    android:paddingTop="12dip"
    android:paddingBottom="12dip"
    style="@style/bigTextWhite" />

</LinearLayout>

//这是你的对话框在onclick按钮事件中出现的方法

public void onClickHelp(View v) {
    final Dialog duDialog = new Dialog(this);
    duDialog.setContentView(R.layout.data_usage);
    duDialog.getWindow().setBackgroundDrawableResource(R.color.title_text);

    duDialog.setTitle("Data Usage"); // I would like to set the color and add button here
    ListView data = (ListView) duDialog.findViewById(R.id.DataUsage);
    duCursor = Data.getAll(db);
    startManagingCursor(duCursor);
    duAdapter = new DataAdapter(duCursor);
    data.setAdapter(duAdapter);
    duDialog.show();

}

关于android - 覆盖 Android 中的对话框标题布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9718426/

相关文章:

qt - “text-overflow” 用于 QT 中 QLabel 的文本渲染

java - SlidingDrawer 启动时半打开

android - Scrollview 没有在 Fragment 中完全滚动,Android

javascript - 在 Dynamics 2011 中调用对话框并将多个 recordID 传递给它

javascript - 要求用户共享的JS对话框, "message"参数什么也没做?

java - 如何在 Firebase 中动态获取 key ?

android - PhoneGap Geolocation 在特殊设备上总是超时

mfc - 在哪里调用 MFC 对话框的 DestroyWindow()?

java - SQL语句给出错误

android - Robolectric:Resources$NotFoundException:带有 Android Gradle 插件 3 的字符串资源 ID