android spinner下拉列表右侧箭头颜色怎么设置
1个回答
展开全部
自定义吧,没有直接设置颜色的
很简单的东西,重写一下Adapter,然后自己对Adapter每个Item布局,在布局里面设置一下点击效果就行了。如:
public class MainActivity extends Activity {
private Spinner mSpinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView(){
mSpinner = (Spinner)findViewById(R.id.spinner);
MyAdapter adapter = new MyAdapter(getResources().getStringArray(R.array.girl_names));
mSpinner.setAdapter(adapter);
}
private class MyAdapter extends BaseAdapter{
private String[] idInt ;
public MyAdapter(String[] idInt){
this.idInt = idInt;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return idInt.length;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return idInt[arg0];
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
if(arg1 == null){
arg1 = getLayoutInflater().inflate(R.layout.spinner_item, null);
}
TextView text = (TextView)arg1.findViewById(R.id.spinner_item_id);
text.setText(idInt[arg0]);
return arg1;
}
}
spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/text_selector"
android:orientation="vertical" >
<TextView
android:layout_margin="10dip"
android:id="@+id/spinner_item_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true" >
</TextView>
</LinearLayout>
然后:text_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@android:color/black"></item>
<item android:state_pressed="false" android:drawable="@android:color/transparent"></item>
</selector>
很简单的东西,重写一下Adapter,然后自己对Adapter每个Item布局,在布局里面设置一下点击效果就行了。如:
public class MainActivity extends Activity {
private Spinner mSpinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView(){
mSpinner = (Spinner)findViewById(R.id.spinner);
MyAdapter adapter = new MyAdapter(getResources().getStringArray(R.array.girl_names));
mSpinner.setAdapter(adapter);
}
private class MyAdapter extends BaseAdapter{
private String[] idInt ;
public MyAdapter(String[] idInt){
this.idInt = idInt;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return idInt.length;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return idInt[arg0];
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
if(arg1 == null){
arg1 = getLayoutInflater().inflate(R.layout.spinner_item, null);
}
TextView text = (TextView)arg1.findViewById(R.id.spinner_item_id);
text.setText(idInt[arg0]);
return arg1;
}
}
spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/text_selector"
android:orientation="vertical" >
<TextView
android:layout_margin="10dip"
android:id="@+id/spinner_item_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true" >
</TextView>
</LinearLayout>
然后:text_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@android:color/black"></item>
<item android:state_pressed="false" android:drawable="@android:color/transparent"></item>
</selector>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询