Как мне создать этот маленький треугольник и цвет подсветки фона на EditText, когда фокус? - PullRequest
0 голосов
/ 23 октября 2018

Мне нужна помощь с этим маленьким треугольником на EditText.Я, вероятно, сделаю изменение фона с помощью селектора, но я не уверен насчет треугольника.И, возможно, когда вы получите пароль EditText, этот треугольник должен соскользнуть вниз.Я буду признателен за любой вклад.Спасибо за ваше время.

Это EditText Я пытаюсь достичь

enter image description here

1 Ответ

0 голосов
/ 23 октября 2018

Попробуйте таким образом

создать макет, подобный этому

<?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>

MainActivity

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);
            }
        });
    }

}

@ drawable / test

<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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...