Spinner popUpBackground无法在Android中设置为透明颜色
第一次使用自定义微调器。我有一个旋转器,背景使用九块图像。喷丝头模式处于对话框模式。现在我为微调器和微调器项设置自定义布局。运行代码,但我没有找到所需的解决方案。即使我已经设置了微调器项的背景,也可以在微调器项的背景上看到角。搜索了很多,但没有找到确切的答案。我使用了来自这个网站的代码,他们的结果是完美的,但当我在那里尝试时,看到微调器项目中的白色背景,整个代码并没有得到想要的结果 main.xml spinner_item.xml 微调器项目列表 函数和适配器 我的结果图像: 在他们的网站上打印样本代码的完美结果,而不是运行他们的代码 在我的应用程序中运行示例代码的非完美结果截图 试试这个Spinner popUpBackground无法在Android中设置为透明颜色,android,spinner,android-spinner,Android,Spinner,Android Spinner,第一次使用自定义微调器。我有一个旋转器,背景使用九块图像。喷丝头模式处于对话框模式。现在我为微调器和微调器项设置自定义布局。运行代码,但我没有找到所需的解决方案。即使我已经设置了微调器项的背景,也可以在微调器项的背景上看到角。搜索了很多,但没有找到确切的答案。我使用了来自这个网站的代码,他们的结果是完美的,但当我在那里尝试时,看到微调器项目中的白色背景,整个代码并没有得到想要的结果 main.xml spinner_item.xml 微调器项目列表 函数和适配器 我的结果图像: 在他们的网站上打
<Spinner
android:id="@+id/spinner1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_below="@+id/scrollView"
android:layout_marginLeft="20dp"
android:background="@drawable/dropdown_button"
android:paddingLeft="2dp"
android:paddingRight="13dp"
android:paddingTop="5dp"
android:spinnerMode="dialog"
android:popupBackground="@android:color/transparent" />//or desired color or drawable
也可以在微调器列表项中尝试此操作
我以前也做过,但还是一样没有效果。
<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinneritem"
android:layout_width="100dp"
android:layout_height="fill_parent"
android:paddingLeft="10dp" />
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/blank_buttons"
android:orientation="horizontal" >
<TextView
android:id="@+id/spinneritemlist"
style="@style/SpinnerText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:textColor="@android:color/black" />
</LinearLayout>
**in onCreate()**
ArrayList<CountryInfo> myCountries;
myCountries = populateList();spinner1 = (Spinner) findViewById(R.id.spinner1);
CountryAdapter myAdapter = new CountryAdapter(this, R.layout.spinner_item, myCountries);
spinner1.setAdapter(myAdapter);
public ArrayList<CountryInfo> populateList()
{
ArrayList<CountryInfo> myCountries = new ArrayList<CountryInfo>();
myCountries.add(new CountryInfo("USA")); // Image stored in /drawable
myCountries.add(new CountryInfo("Sweden"));
myCountries.add(new CountryInfo("Canada"));
return myCountries;
}
public class CountryAdapter extends ArrayAdapter<CountryInfo>
{
private Activity context;
ArrayList<CountryInfo> data = null;
public CountryAdapter(Activity context, int resource, ArrayList<CountryInfo> data)
{
super(context, resource, data);
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{ // Ordinary view in Spinner, we use android.R.layout.simple_spinner_item
return super.getView(position, convertView, parent);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent)
{ // This view starts when we click the spinner.
View row = convertView;
if(row == null)
{
LayoutInflater inflater = context.getLayoutInflater();
row = inflater.inflate(R.layout.spinner_item_list, parent, false);
}
CountryInfo item = data.get(position);
if(item != null)
{ // Parse the data from each object and set it.
TextView myCountry = (TextView) row.findViewById(R.id.spinneritemlist);
if(myCountry != null)
myCountry.setText(item.getCountryName());
}
return row;
}
}
<Spinner
android:id="@+id/spinner1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_below="@+id/scrollView"
android:layout_marginLeft="20dp"
android:background="@drawable/dropdown_button"
android:paddingLeft="2dp"
android:paddingRight="13dp"
android:paddingTop="5dp"
android:spinnerMode="dialog"
android:popupBackground="@android:color/transparent" />//or desired color or drawable
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:orientation="horizontal" >
<TextView
android:id="@+id/spinneritemlist"
style="@style/SpinnerText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:background="@drawable/blank_buttons"
android:textColor="@android:color/black" />
</LinearLayout>