gpt4 book ai didi

android - 样式 android 微调器

转载 作者:IT老高 更新时间:2023-10-28 22:20:24 25 4
gpt4 key购买 nike

我正在尝试让我的 android 应用程序更时尚一点,并取得了一些进展,但微调器下拉菜单给我带来了麻烦。我有一个屏幕截图可以向您展示问题:

How do I get rid of the white background

我想要的是背景中的白色框是透明的,就像在后屏幕上的灰色覆盖层一样,与下拉菜单之外的屏幕的其余部分一样。

如果我没记错的话,Android 4.0,API 15。

按照要求,这是我目前的做法。这些是我认为相关的 fragment ,但我可能遗漏了一些东西。

这是微调器的 xml:

<Spinner
android:id="@+id/edit_countrySpinner"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="@array/edit_countryArray"
android:gravity="center"
android:prompt="@string/country_prompt" />

在我的 values/style.xml 中。如果我在这里更改背景的颜色,对话框中的背景会发生变化,但所有其余的背景也会发生变化。我还没有弄清楚如何在下拉对话框中更改背景。

<style name="appcin" parent="@android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:spinnerStyle">@style/spinnerStyle</item>
<item name="android:spinnerItemStyle">@style/SpinnerItem</item>
<item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item> -->
<item name="android:background">#FFFFFF</item>
</style>
<style name="spinnerStyle">
<item name="android:background">@drawable/pink_white_dropdown</item>
<item name="android:clickable">true</item>
</style>
<style name="SpinnerItem">
<item name="android:textColor">#993399</item>
<item name="android:background">@drawable/pink_white_dropdown</item>
<item name="android:maxHeight">10dip</item>
</style>
<style name="SpinnerDropDownItem">
<item name="android:textColor">#993399</item>
<item name="android:background">#FFFFFF</item>
</style>

我已经尝试将它添加到应用主题中,但它们都没有任何区别,背景仍然是白色的。

<...theme....>
<item name="android:dropDownListViewStyle">@style/DropDownStyle</item>
<item name="android:dropDownSpinnerStyle">@style/DropDownStyle</item>
<item name="android:dropDownSelector">@style/DropDownStyle</item>
</... theme ...>
<style name="DropDownStyle">
<item name="android:background">#FFF000</item>
<item name="android:popupBackground">#FFF000</item>
<item name="android:cacheColorHint">#FFF000</item>
</style>

在 drawable/pink_white_dropdown 中,只为所有情况显示相同的图像。 pink_white_arrow 是我制作的 9patch 图像。有很多指南,here's one I found by 30sec on google .

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/pink_white_arrow"/>
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="@drawable/pink_white_arrow"/>
<item android:state_pressed="true"
android:drawable="@drawable/pink_white_arrow"/>
<item android:state_pressed="false"
android:drawable="@drawable/pink_white_arrow"/>
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/pink_white_arrow"/>
<item android:state_enabled="true"
android:drawable="@drawable/pink_white_arrow"/>
<item android:state_focused="true"
android:drawable="@drawable/pink_white_arrow"/>
<item
android:drawable="@drawable/pink_white_arrow"/>
</selector>

我认为在这些文件中的某处应该将某些内容设为透明,但我不知道在哪里。

最佳答案

移除 SpinnerStyle 背景属性。

删除这个:

<style name="spinnerStyle">
<item name="android:background">@drawable/whitish_rectangle</item>
</style>

这是绘制背景白色矩形的原因。

以您问题中的代码为基础,下面是一个关于如何设置 Spinner 样式的基本示例:

styles.xml 文件设置 SpinnerItemSpinnerDropDownItem 的样式:

<resources>
<style name="customtheme" parent="@android:style/Theme.Light">
<item name="android:spinnerItemStyle">@style/SpinnerItem</item>
<item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
</style>
<style name="SpinnerItem">
<item name="android:textColor">#993399</item>
<item name="android:background">@drawable/my_rectangle</item>
</style>
<style name="SpinnerDropDownItem">
<item name="android:textColor">#993399</item>
<item name="android:background">@drawable/my_rectangle</item>
</style>
</resources>

为了测试,我创建了一个颜色鲜艳的可绘制形状,称为 my_rectangle.xml。用你自己的drawable替换它:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ff0000" />
<stroke
android:width="1dp"
android:color="#888888" />
</shape>

Spinner 添加到 Activity 的 布局中:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="40dip">
<Spinner
android:id="@+id/edit_countrySpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/location_names"/>
</LinearLayout>

这会产生:

enter image description here

背景中没有白色方 block 。

关于android - 样式 android 微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13703233/

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