Android:点击和输入文本时 EditText 透明度发生变化

Android: EditText transparency change on click and text entry

如何使 EditText(包括下划线和 android:hint)在没有输入文本且未被点击时具有 50% 的透明度,然后在被点击时更改为 100%单击或已输入文本?

另外,透明度100%时(点击或输入文字时),如何将下划线(非提示)颜色改为橙色?

使用以下代码

mEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                // If has focus then change the alpha to 1
                mEditText.setAlpha(1);
                // Set orange color filter
                mEditText.getBackground().setColorFilter(Color.argb(255, 255, 165, 0), PorterDuff
                        .Mode.SRC_IN);
            } else {
                // When focus is lost, check if some text has been entered.
                // If not then set the alpha to 0.5f (50% transparent)
                if (TextUtils.isEmpty(mEditText.getText().toString())) {
                    mEditText.setAlpha(0.5f);
                    // Clear the color filter
                    mEditText.getBackground().clearColorFilter();
                }
            }
            mEditText.invalidate();
        }
    });