How to add floating label on Spinner

前端 未结 10 1727
Happy的楠姐
Happy的楠姐 2020-12-12 14:46

After using the Android Design Support Library\'s TextInputLayout to place a floating label above an EditText component, I was wondering if there is a way to add a floating

10条回答
  •  半阙折子戏
    2020-12-12 15:17

    I achieved this by using an AutoCompleteTextView, disabling the keyboard and showing the options on touch.

    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.locations));
    
    AutoCompleteTextView mTextView = (AutoCompleteTextView) findViewById(R.id.location);
    
    mTextView.setAdapter(adapter);
    mTextView.setKeyListener(null);
    mTextView.setOnTouchListener(new View.OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent event){
            ((AutoCompleteTextView) v).showDropDown();
            return false;
        }
    });
    

提交回复
热议问题