How to change layout of spinner in Android

后端 未结 3 970
甜味超标
甜味超标 2021-02-06 14:32

\"\"

When O click on this spinner it gives a big dropdown:

3条回答
  •  孤城傲影
    2021-02-06 14:51

    Follow these steps. I have already implemented this.

    (1) Do not use spinner. Instead use a button with background set to "@android:drawable/btn_dropdown". This button will look exactly same as native spinner. If you want it to look any different use your own resource.

    (2) You need to override dialog class and invoke it on button click. In the constructor of the extended Dialog class, you can use your own layout resource.

    this.setContentView(R.layout.dropdownlist);
    

    You can also change window look and feel using following code

    WindowManager.LayoutParams lp = getWindow().getAttributes();
    lp.width = dlgWidth;
    lp.height = dlgHeight;
    lp.dimAmount = 0;
    getWindow().setAttributes(lp);
    getWindow().setBackgroundDrawableResource(mBackgroundResId);
    

    (3) You can have a list view in your custom layout and on "OnItemClickListener" of the list, dismiss the dialog and do what you need to do further.

    I hope this helps.

提交回复
热议问题