Android 聚焦时,我应该如何在EditText上创建小三角形和背景高亮颜色?

Android 聚焦时,我应该如何在EditText上创建小三角形和背景高亮颜色?,android,xml,android-layout,Android,Xml,Android Layout,我需要关于EditText上的这个小三角形的帮助。我可能会用选择器更改背景突出显示,但我不确定三角形。 当您进入密码EditText时,三角形可能会向下滑动。如有任何意见,我将不胜感激。谢谢你抽出时间 这是我试图实现的EditText 试试这种方法 创建这样的布局 @可拉伸/试验 在布局中添加固定三角形。显示隐藏(或移动)焦点上的三角形到编辑文本。至于颜色-创建一个状态列表,可使用默认状态和焦点状态绘制,并为这些状态设置不同的背景颜色。要制作三角形幻灯片,您可以自定义SeekBar,每次使用s

我需要关于
EditText
上的这个小三角形的帮助。我可能会用选择器更改背景突出显示,但我不确定三角形。 当您进入密码
EditText
时,三角形可能会向下滑动。如有任何意见,我将不胜感激。谢谢你抽出时间

这是我试图实现的
EditText

试试这种方法

创建这样的布局

@可拉伸/试验



在布局中添加固定三角形。显示隐藏(或移动)焦点上的三角形到编辑文本。至于颜色-创建一个状态列表,可使用默认状态和焦点状态绘制,并为这些状态设置不同的背景颜色。要制作三角形幻灯片,您可以自定义
SeekBar
,每次使用
setProgress更改进度(整数进度,布尔动画)
.VerticalSeekBar项目:@Rohit5k2所以我应该把三角形的图像放在布局中,并像这样处理。谢谢大家的建议。谢谢Nilesh。谢谢。作为一个兴趣点,你能告诉我,在我有菜单的抽屉里,我应该如何做同样的事情吗?我的意思是说,假设我有菜单,我应该如何做同样的事情。在抽屉中的菜单中,只有标题和图标。我们是否应该在菜单中进行自定义布局并充气以获得上述外观?@UmangBurman是的,您可以使用自定义导航检查我的答案,这将给您一个提示啊,非常感谢:)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rootView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">

        <ImageView
            android:id="@+id/imgEmail"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:src="@drawable/test" />

        <EditText
            android:id="@+id/edtEmail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginTop="5dp"
            android:layout_marginEnd="10dp"
            android:imeOptions="actionNext"
            android:inputType="textEmailAddress" />

    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">

        <ImageView
            android:id="@+id/imgPass"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:visibility="invisible"
            android:src="@drawable/test" />

        <EditText
            android:id="@+id/edtPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginTop="5dp"
            android:layout_marginEnd="10dp"
            android:imeOptions="actionNext"
            android:inputType="textPassword" />
    </LinearLayout>

</LinearLayout>
public class MainActivity extends AppCompatActivity {

    EditText edtEmail, edtPassword;

    ImageView imgPass,imgEmail;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        edtEmail = findViewById(R.id.edtEmail);
        edtPassword = findViewById(R.id.edtPassword);

        imgEmail = findViewById(R.id.imgEmail);
        imgPass = findViewById(R.id.imgPass);

        edtEmail.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus)
                    imgEmail.setVisibility(View.VISIBLE);
                else
                    imgEmail.setVisibility(View.INVISIBLE);
            }
        });

        edtPassword.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus)
                    imgPass.setVisibility(View.VISIBLE);
                else
                    imgPass.setVisibility(View.INVISIBLE);
            }
        });
    }

}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
    <path
        android:pathData="M0,12l0,12 11.5,-5.7c6.3,-3.2 11.5,-6 11.5,-6.3 0,-0.3 -5.2,-3.1 -11.5,-6.3l-11.5,-5.7 0,12z"
        android:strokeColor="#00000000"
        android:fillColor="#000000"/>
</vector>