美文网首页我爱编程
时间、滑动、滚轮选择器

时间、滑动、滚轮选择器

作者: 3Q竹林 | 来源:发表于2018-06-18 09:36 被阅读120次
  • 时间选择器:
    1.放入xml布局中使用的有:DatePicker和TimePicker两种实现动态输入日期和时间的功能,都是继承与NumberPicker的。
    2.对话框形式的有:DatePickerDialog和TimePickerDialog两种实现动态输入日期和时间的对话框
    这四种都会根据手机中当前版本,是会自行调整显示样式的。

  • 滑动(开关)选择器:

      <TextSwitcher
          android:layout_width="match_parent"
          android:layout_height="match_parent" />
    
      <ViewSwitcher
          android:layout_width="match_parent"
          android:layout_height="match_parent" />
    
      <ImageSwitcher  ----可以像ViewPager一样,实现图片的左右切换功能
          android:layout_width="match_parent"
          android:layout_height="match_parent" />
    
      <android.support.v7.widget.SwitchCompat
          android:layout_width="match_parent"
          android:layout_height="match_parent" />
    

    而更改默认Switch的样式:

      <!--自定义switch的按钮和轨迹颜色theme-->    
      <style name="mySwitch" parent="Theme.AppCompat.Light">  
      <!-- switch 打开时的按钮的颜色 轨迹颜色默认为30%(看效果就明白30%是怎么回事了)这个颜色 -->  
      <item name="colorControlActivated">@android:color/holo_green_dark</item>  
      <!--  switch关闭时的按钮的颜色 -->  
      <item name="colorSwitchThumbNormal">@color/colorAccent</item>  
      <!-- switch关闭时的轨迹的颜色 30%这个颜色 -->  
      <item name="android:colorForeground">@color/colorPrimaryDark</item>  
    </style>
    //然后在布局文件中通过android:theme="@style/mySwitch"设置即可;
    
    
  • 自定义Switch :

    首先实现thumb_selector.xml 拇指选择器:

      <?xml version="1.0" encoding="utf-8"?>  
      <selector xmlns:android="http://schemas.android.com/apk/res/android">  
          <!--选中时的滑块图片-->  
      <item android:drawable="@drawable/thumb_on" android:state_checked="true"/>  
          <!--正常情况滑块图片-->  
      <item android:drawable="@drawable/thumb"/>  
      </selector>  
          
      然后实现track_selector.xml :
      <?xml version="1.0" encoding="utf-8"?>  
          <selector xmlns:android="http://schemas.android.com/apk/res/android">  
          <!--打开时switch轨迹图片-->  
          <item android:state_pressed="true"  android:drawable="@drawable/track_on" />  
          <!--按压时switch轨迹图片-->  
          <item android:state_checked="true"  android:drawable="@drawable/track_press" />  
          <!--正常状态switch轨迹图片-->  
          <item  android:drawable="@drawable/track_nomal" />  
        
      </selector>  
    
    

    在布局中正常使用:

     <android.support.v7.widget.SwitchCompat  
        android:layout_marginTop="10dp"  
        android:id="@+id/CustomSwitchCompat"  
        android:layout_width="wrap_content"  
        android:minWidth="40dp"  
        android:minHeight="20dp"  
        android:layout_height="wrap_content" />  
    

    在activity中设置自定义的资源:

      //设置自定义的thumb和track  
      customSwitchCompat.setThumbResource(R.drawable.thumb_selector);  
      customSwitchCompat.setTrackResource(R.drawable.track_selector);  
      //设置Switch开关事件监听  
      customSwitchCompat.setOnCheckedChangeListener(this);  
    
  • wheelView滚轮文本选择器:
    wheelView的效果就是将文字或数字等,放到"一个"滚轮中滚动选择,另外wheelView是第三方控件,并不是v7包下的;

    推荐三个好网址:
    http://blog.csdn.net/ywl5320/article/details/44730457
    http://blog.csdn.net/wulianghuan/article/details/41549189/
    http://blog.csdn.net/lmj623565791/article/details/23382805

相关文章

网友评论

    本文标题:时间、滑动、滚轮选择器

    本文链接:https://www.haomeiwen.com/subject/poogeftx.html