NiceSpinner 是 Android 端的一款第三方控件,自带箭头动画效果

GitHub地址

效果图如下:



目录

1. 导入模块

2. 代码测试



1. 导入模块

Github 下载并导入模块

或者在 build.gradle 中修改:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

dependencies {
    compile 'com.github.arcadefire:nice-spinner:1.3.1'
}

建议导入模块,可以修改。



2. 代码测试

在 activity_main.xml 文件中加入:

<org.angmarch.views.NiceSpinner
    android:id="@+id/nice_spinner"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    app:arrowTint="@color/light_gray"
    app:textTint="@color/myBlack"
    app:dropDownListPaddingBottom="60dp"
    android:layout_marginEnd="12dp"
    android:layout_marginRight="12dp"/>
nametypeinfo
arrowTintcolorsets the color on the drop-down arrow
hideArrowbooleanset whether show or hide the drop-down arrow
arrowDrawablereferenceset the drawable of the drop-down arrow
textTintcolorset the text color
dropDownListPaddingBottomdimensionset the bottom padding of the drop-down list
backgroundSelectorintegerset the background selector for the drop-down list rows

在 MainActivity.java 中加入:

private NiceSpinner niceSpinner;
List<String> spinnerData = new LinkedList<>(Arrays.asList("一月", "二月", "三月", "四月",
        "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"));
niceSpinner = findViewById(R.id.nice_spinner);
 
 
niceSpinner.attachDataSource(spinnerData);
niceSpinner.setBackgroundResource(R.drawable.textview_round_border);
niceSpinner.setTextColor(Color.WHITE);
niceSpinner.setTextSize(13)
niceSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {}
})


textview_round_border.xml (设置圆角等属性,放在 drawable 目录下)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- view背景色 -->
    <solid android:color="#52a2e2" />
    <!-- 边框颜色 宽度 -->
    <stroke
        android:width="1dip"
        android:color="#52a2e2" />
    <!-- 边框圆角 -->
    <corners
        android:bottomRightRadius="6dp"
        android:topRightRadius="6dp"
        android:bottomLeftRadius="6dp"
        android:topLeftRadius="6dp"/>
</shape>


在 nice-spinner-master/src/main/java/NiceSpinner 目录下可以修改属性


Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐