Android第三方开源下拉框NiceSpinner使用详解

  

android原生的下拉框转轮基本上可以满足android开发对于下拉选项的设计需求,但现在越来越流行的下拉框不满足于android原生提供的下拉框转轮所提供的设计样式,而改用自定制或者第三方设计的下拉框转轮。
  

  

NiceSpinner是一个第三方开源的下拉框旋转器,其在github上的项目主页是:https://github.com/arcadefire/nice-spinner
  ,NiceSpinner原设计效果如动图所示:,

  

 Android第三方开源下拉框NiceSpinner使用详解

  

但是通常开发者对于可能还需要对于下拉框中出现的文字和样式进行二次开发,比如如果希望NiceSpinner的选中文本颜色或者下拉弹出框中的文字有些变化,则需要重新二次定制NiceSpinner代码项目中的NiceSpinnerBaseAdapter, NiceSpinnerBaseAdapter中的getView返回的观点表现形式即为下拉框中的结果:,
  

     //这个方法将返回下拉列表的形制,可以在这里修改和二次定制开发。//张菲尔注解   @Override   @SuppressWarnings (“unchecked”)   公众视线getView (int位置、视图convertView ViewGroup父){   TextView TextView;      如果(convertView==null) {   convertView=视图。充气(mContext出来。spinner_list_item, null);   textView=(textView) convertView.findViewById (R.id.tv_tinted_spinner);      如果(Build.VERSION。SDK_INT祝辞=Build.VERSION_CODES.JELLY_BEAN) {   textView.setBackground (ContextCompat。getDrawable (mContext mBackgroundSelector));   }      convertView。setTag(新ViewHolder (textView));   其他}{   textView=((ViewHolder) convertView.getTag ()) .textView;   }      textView.setText (getItem(位置).toString ());   textView.setTextColor (mTextColor);//这里是被张菲尔修改的,用于改变下拉列表的文字颜色。   textView.setTextColor (Color.RED);      返回convertView;   }   之前      

修改后,写一个小演示演示,测试的MainActivity。Java:
  

        包zhangphil.demo;      进口java.util.Arrays;   进口java.util.LinkedList;   进口org.angmarch.views.NiceSpinner;   进口android.app.Activity;   进口android.graphics.Color;   进口android.os.Bundle;         公开课MainActivity延伸活动{      @Override   保护空白>   & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android "   xmlns:工具=" http://schemas.android.com/tools "   android: layout_width=" match_parent "   android: layout_height=" match_parent "   工具:上下文=皕hangphil.demo.MainActivity”比;      & lt; org.angmarch.views.NiceSpinner   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_centerHorizontal=" true "   android: id=癅 + id/nice_spinner”/比;      & lt;/RelativeLayout>      之前      

代码运行结果:,

  

 Android第三方开源下拉框NiceSpinner使用详解

  

 Android第三方开源下拉框NiceSpinner使用详解

  

我把NiceSpinner的代码库(库和实例演示)全部作为一个文件目录推到github上面,项目主页是:https://github.com/zhangphil/zhangphil-nice-spinner
  

  

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

Android第三方开源下拉框NiceSpinner使用详解