在Android中覆盖对话框标题布局

5

我为我的Android应用程序创建了一个自定义主题,计划覆盖对话框标题使用的布局。我发现在标准Android Theme中有一个属性看起来像是要修改的属性。

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

但是当我试图在我的主题中覆盖它时
<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>

我看到了以下错误:

找不到与给定名称匹配的资源:属性'android:dialogTitleDecorLayout'

为什么我无法更改它?我该如何知道哪些属性可以更改,哪些不能?


你能展示一下样式的完整XML文件吗?也许你在那里缺少了Android的XML模式? - Genry
1个回答

1

无法通过此方式覆盖该项。您必须使用所需的布局自定义对话框,然后在布局中应用主题以满足您的要求。

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>

//这是当您点击按钮事件时对话框出现的方法

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();

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接