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