gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:18:29 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com