gpt4 book ai didi

java - 更改对话框微调器的弹出背景颜色

转载 作者:行者123 更新时间:2023-12-02 02:31:42 26 4
gpt4 key购买 nike

我想更改对话框微调器的 popupBackground 颜色。

在我的activity.xml中:

<Spinner
android:id="@+id/mCategorySpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/textView7"
android:entries="@array/recipeCategory"
android:spinnerMode="dialog"
android:popupBackground="@color/colorPrimary"
android:textAlignment="center" />

在我的activity.java中:

categorySpinner=(Spinner) findViewById(R.id.mCategorySpinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.recipeCategory, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
categorySpinner.setPrompt("Choose category");
categorySpinner.setAdapter(new NothingSelectedSpinnerAdapter(
adapter,
R.layout.category_spinner_row_nothing_selected,
this));

如果我更改 XML 中的 android:popupBackground,什么也不会发生,它仍然是默认的白色。
但是,如果我更改背景,它会起作用,但不适用于对话框的背景。

最佳答案

您可以像这样更改背景颜色和下拉图标

第1步:在drawable文件夹中创建一个名为background.xml的文件作为微调器的背景。

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent" />
<corners android:radius="5dp" />
<stroke
android:width="1dp"
android:color="@color/darkGray" />
</shape>

第 2 步:现在将此背景应用到 xml 文件中的微调器上

 android:background="@drawable/background"

关于java - 更改对话框微调器的弹出背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46987939/

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