How to consistently set EditText Selected Underline Color Programmatically

前端 未结 5 2099
情深已故
情深已故 2021-02-20 09:05

I\'m trying to build a renderer for Xamarin Forms. The renderer needs to set the EditText underline color to \"Active Color\" when selected and \"Hint Color\" when

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-20 09:39

    To change color you can use below code

     editText.getBackground().mutate().setColorFilter(your_color), PorterDuff.Mode.SRC_ATOP);
    

    And to set different color underline for EditText view on focus change

        editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    editText.getBackground().mutate().setColorFilter(getResources().getColor(android.R.color.holo_purple), PorterDuff.Mode.SRC_ATOP);
                }else {
                    editText.getBackground().mutate().setColorFilter(getResources().getColor(android.R.color.holo_red_dark), PorterDuff.Mode.SRC_ATOP);
                }
            }
        });
    

提交回复
热议问题