如何使添加到 AlertDialog 的自定义布局中 TextView 的 textAppearance 与 Dialog 的相匹配?
How can I make the textAppearance of TextView inside custom layout added to AlertDialog match the Dialog's?
我有这个自定义布局,因为我想要一个带有 TextView 下方 的 ListView,并且我想处理列表项上的单击,这样对话框就不会关闭。 (AlertDialog 将在其 ListView 上方显示自己的消息视图。)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="14dp"
android:paddingEnd="10dp"
>
<ListView
android:id="@+id/optionList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:choiceMode="singleChoice"
android:divider="@null"
/>
<TextView
android:id="@+id/messageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="5dp"
/>
</LinearLayout>
我做了一个假的设置,我在对话框的 TextView 和我的布局中都放置了文本。结果截图。
我什至尝试将 style="?android:attr/textAppearanceMedium"
放在我的布局中的 @id/messageView 中,因为 alert_dialog.xml
有它。它使文本大于对话框的消息。而且颜色不匹配,太浅(好像是Activity的默认颜色)。
我什至尝试使用构建器的 LayoutInflater,这是文档所说的。
val infl = builder.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = infl.inflate(R.layout.dialog_report_profile, null)
builder.setView(view)
您可以随时将 style="?android:attr/textAppearanceMedium"
AND android:color="#000"
都放在您的 TextView
.
或者,您可以将其添加到您的 res/styles。xml:
<style name="DialogMessageText" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@android:color/black</item>
</style>
并将此行放入您的 TextView:style="@style/DialogMessageText"
我有这个自定义布局,因为我想要一个带有 TextView 下方 的 ListView,并且我想处理列表项上的单击,这样对话框就不会关闭。 (AlertDialog 将在其 ListView 上方显示自己的消息视图。)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="14dp"
android:paddingEnd="10dp"
>
<ListView
android:id="@+id/optionList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:choiceMode="singleChoice"
android:divider="@null"
/>
<TextView
android:id="@+id/messageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="5dp"
/>
</LinearLayout>
我做了一个假的设置,我在对话框的 TextView 和我的布局中都放置了文本。结果截图。
我什至尝试将 style="?android:attr/textAppearanceMedium"
放在我的布局中的 @id/messageView 中,因为 alert_dialog.xml
有它。它使文本大于对话框的消息。而且颜色不匹配,太浅(好像是Activity的默认颜色)。
我什至尝试使用构建器的 LayoutInflater,这是文档所说的。
val infl = builder.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = infl.inflate(R.layout.dialog_report_profile, null)
builder.setView(view)
您可以随时将 style="?android:attr/textAppearanceMedium"
AND android:color="#000"
都放在您的 TextView
.
或者,您可以将其添加到您的 res/styles。xml:
<style name="DialogMessageText" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@android:color/black</item>
</style>
并将此行放入您的 TextView:style="@style/DialogMessageText"