【问题标题】:Overriding dialog title layout in Android覆盖Android中的对话框标题布局
【发布时间】:2012-03-31 21:13:00
【问题描述】:

我在我的 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>

我看到以下错误:

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

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

【问题讨论】:

  • 您能显示该样式的完整 xml 文件吗?可能是你在那里缺少 android 的 xml 架构吗?

标签: android layout dialog styles themes


【解决方案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>

//这是你的对话框出现在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();

}

【讨论】:

    猜你喜欢
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    相关资源
    最近更新 更多