gpt4 book ai didi

android - 使用 AlertDialog.Builder.setCustomTitle() 时设置默认文本样式

转载 作者:太空狗 更新时间:2023-10-29 13:38:21 27 4
gpt4 key购买 nike

这可能很简单,但我无法在任何地方找到答案。

我正在为我的警告对话框使用 setCustomTitle,以便将我自己的 View 用于对话框标题:

View customTitle = getLayoutInflater().inflate(R.layout.dialog_title, null);
new AlertDialog.Builder(AddBusActivity.this).setCustomTitle(customTitle).(some more stuff).show();

和 dialog_title.xml:

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

<TextView android:text="My Title"
android:id="@+id/title"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="right|center_vertical">
</TextView>
</LinearLayout>

我的问题是使标题 TextView 使用默认的对话框标题样式。在我的设备中,警告对话框的背景是深色的,因此文本必须是明亮的,但在其他设备中可能会有所不同。

我尝试将 android:textAppearance="@android:style/TextAppearance.DialogWindowTitle" 添加到 TextView,但它导致文本为黑色,但不是正确的风格。

我该如何解决这个问题?

最佳答案

我在样式和颜色方面遇到了类似的问题,但通过使用自定义对话框而不是 AlertDialog 解决了这个问题。

1)我的代码

AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle(mName);
...
mDialog = builder.create();
mDialog.show();

改为

dialog = new Dialog(mContext);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_custom_title);
// initializing Views
dialog.show();

2) 在layout.dialog_custom_title 中设置需要的样式(背景和颜色)

<LinearLayout xmlns: android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/dialogs_background"
android:orientation="vertical" >
...
<TextView
...
android:textColor="@color/TxtLightBlue"
android:textSize="@dimen/text_size_default"
/>
...

希望对大家有帮助。

关于android - 使用 AlertDialog.Builder.setCustomTitle() 时设置默认文本样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8447225/

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