android spinner修改样式

      例子:http://www.eoeandroid.com/thread-92092-1-1.html

 

做到一种样式  android 的spinner本身背景样式要黑色的 ,而spinner里的字体也是黑色的 ,spinner 控件的属性里设置TextColor没用  网上找了下  需要定义xml 文件来定义样式   和自定义按钮控件类似;

 

1,首先定义spinenr本身背景的样式:

 

 

Java代码

<?xml version="1.0" encoding="utf-8"?> 

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:state_pressed="true" android:drawable="@drawable/droplist_down" /> 

    <item android:state_focused="true" android:drawable="@drawable/droplist_focus" /> 

    <item android:drawable="@drawable/droplist" /> 

</selector> 

 

 

2,在xml里引用

 

 

Java代码

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 

    android:orientation="vertical" 

    android:layout_width="fill_parent" 

    android:layout_height="fill_parent"> 

     <Spinner  

        android:id="@+id/glucosespin" 

        android:layout_marginLeft="20dp" 

        android:background="@drawable/drop_list" 

        android:layout_width="95dp" 

        android:layout_height="20dp" 

        android:layout_centerHorizontal="true"/> 

</LinearLayout> 

 

 

这样spinner背景就变成了自定义的黑色了

 

3,定义spinner里的字体样式

 

Java代码

<?xml version="1.0" encoding="utf-8"?> 

 

 <TextView xmlns:android="http://schemas.android.com/apk/res/android" 

     android:id="@android:id/text1" 

     style="?android:attr/spinnerDropDownItemStyle" 

     android:singleLine="true" 

     android:layout_width="fill_parent" 

     android:layout_height="wrap_content" 

     android:ellipsize="marquee" 

     android:layout_gravity="center_vertical" 

     android:textColor="#84DB18" 

     android:textSize="12sp"/> 

 4,定义弹出的选择样式

 

Java代码

<?xml version="1.0" encoding="utf-8"?> 

 

 <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 

     android:id="@android:id/text1" 

     style="?android:attr/spinnerDropDownItemStyle" 

     android:singleLine="true" 

     android:layout_width="fill_parent" 

     android:layout_height="?android:attr/listPreferredItemHeight" 

     android:ellipsize="marquee" 

     android:textColor="#84DB18" 

     android:background="#424142"/> 

 

这样,一个spinner就完全变身了额。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值