單選滾動選擇器、diy豐富、有阻尼效果、簡單美觀、觸摸or點擊模式 (Rolling Selector, Diy Rich, Damping Effect, Simple and Beautiful, Touch or Click Mode) Github地址 YangsBryant/DSelect ...
單選滾動選擇器、diy豐富、有阻尼效果、簡單美觀、觸摸or點擊模式 (Rolling Selector, Diy Rich, Damping Effect, Simple and Beautiful, Touch or Click Mode)
Github地址
(Github排版比較好,建議進入這裡查看詳情,如果覺得好,點個star吧!)
引入module
allprojects {
repositories {
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
implementation 'com.github.YangsBryant:DSelectorBryant:1.0.2'
主要代碼
public class MainActivity extends AppCompatActivity { DSelectorPopup dSelectorPopup; ConstraintLayout constraintLayout; ArrayList<String> list = new ArrayList<>(); Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); for (int i = 0; i <= 10; i++) { list.add("YMF"+i); } dSelectorPopup = new DSelectorPopup(this,list); dSelectorPopup.build(); constraintLayout = findViewById(R.id.main); button = findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //彈出窗體 dSelectorPopup.popOutShadow(constraintLayout); } }); /*點擊監聽器 Tips:實現此監聽器,點擊button也會返回當前選中項的下標和文本,因此button既可以當做取消用,也可以當做確定用*/ dSelectorPopup.setSelectorListener(new DSelectorPopup.SelectorClickListener() { @Override public void onSelectorClick(int position, String text) { Toast.makeText(MainActivity.this,text,Toast.LENGTH_SHORT).show(); //縮回窗體 dSelectorPopup.dismissPopup(); } }); //滑動監聽器 /*dSelectorPopup.setSelectoMoverListener(new DSelectorPopup.SelectorMoveListener() { @Override public void onSelectorMove(int position, String text) { Toast.makeText(MainActivity.this,text,Toast.LENGTH_SHORT).show(); } });*/ } }
參數實例
dSelectorPopup.setOffset(5) .setTextSize(30) .setTextcolor_selection(getResources().getColor(R.color.colorAccent)) .setTextcolor_unchecked(getResources().getColor(R.color.colorPrimary)) .setGradual_color(0xffD81B60) .setTitleText("我是標題") .setTitleColor(getResources().getColor(R.color.colorPrimary)) .setTitleSize(25) .setButton_background(getResources().getDrawable(R.drawable.popup_bg)).build();
Tips:分割線的顏色值為:0xff 加上16進位顏色值,例如:0xffD81B60
DSelectorBryant屬性大全
方法名 | 屬性 |
build() | 參數設置完畢,在最後build一下 |
setHeights(int height) | PopupWindow的高度,單位dp |
isOutside(boolean bl) | 點擊彈窗外是否消失,預設true |
setSeletion(int offset) | 對話框中當前項上面和下麵的項數 |
setOffset(int seletion) | 預設選中項 |
setTextSize(int size) | 文本字體大小 |
setTextcolor_selection(int textcolor_selection) | 選中文本顏色 |
setTextcolor_unchecked(int textcolor_unchecked) | 未選中文本顏色 |
setGradual_color(int gradual_color) | 分割線顏色 |
setFining(boolean fining) | 是否開啟分割線兩端變細,預設true |
setTitleText(String titleText) | 標題的文字 |
setTitleSize(int titleSize) | 標題文字大小 |
setTitleColor(int titleColor) | 標題文字顏色 |
setButtonText(String buttonText) | 按鈕文本 |
setButtonSize(int buttonSize) | 按鈕文字大小 |
setButtonColor(int buttonColor) | 按鈕文字顏色 |
setButton_background(Drawable drawable) | 按鈕背景 |
setButtonWidt(int buttonWidt) | 按鈕寬度,單位dp |
setButtonHeight(int buttonHeight) | 按鈕高度,單位dp |
popOutShadow(View view) | 顯示彈窗 |
dismissPopup() | 關閉彈窗 |
setSelectorListener(SelectorClickListener selectorListener) | 點擊監聽器 |
setSelectoMoverListener(SelectorMoveListener selectoMoverListener) | 滑動監聽器 |