How to make the textHint go to the top of the editText by cutting the edge?

0

I made this custom editText

but I would like to achieve this transition effect when you click on the editText the textHint goes to the top of the editText cutting the border and staying like this:

I would like to do it by code, not using the android.support.design.widget.TextInputLayout as there are several things I want to customize and I can not do it using that widget.

I leave the code:

MainActivity.java

public class MainActivity extends AppCompatActivity {
private LinearLayout linearLayoutFechaNacimiento;
private TextInputEditText textInputEditTextFechaNacimiento;
private TextView textViewFechaNacimientoContador;

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

    //Hacemos la referencia
    linearLayoutFechaNacimiento = findViewById(R.id.lLFechaNacimiento);
    textInputEditTextFechaNacimiento = findViewById(R.id.etFechaNacimiento);
    textViewFechaNacimientoContador = findViewById(R.id.tvFechaNacimientoContador);

    //Controlamos el foco en el EditText
    textInputEditTextFechaNacimiento.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @SuppressLint("ResourceAsColor")
        @Override
        public void onFocusChange(View view, boolean b) {
            if(b){
                linearLayoutFechaNacimiento.setBackgroundResource(R.drawable.border_focus);
                textViewFechaNacimientoContador.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
            } else{
                linearLayoutFechaNacimiento.setBackgroundResource(R.drawable.border_default);
                textViewFechaNacimientoContador.setTextColor(Color.DKGRAY);
            }
        }
    });
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
    android:layout_width="350dp"
    android:layout_height="70dp"
    android:layout_gravity="center_vertical|center_horizontal"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/lLFechaNacimiento"
        android:layout_width="350dp"
        android:layout_height="50dp"
        android:paddingStart="10dp"
        android:paddingEnd="10dp"
        android:weightSum="1"
        android:orientation="horizontal"
        android:background="@drawable/border_default">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/etFechaNacimiento"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".9"
            android:backgroundTint="@android:color/transparent"
            android:inputType="date"
            android:textStyle="italic"
            android:hint="Fecha de Nacimiento"/>

        <ImageButton
            android:id="@+id/imgbtnFechaNacimiento"
            android:layout_width="1dp"
            android:layout_height="30dp"
            android:layout_weight=".1"
            android:layout_gravity="center_vertical"
            android:background="@drawable/ic_calendar_black_20dp"/>

    </LinearLayout>

    <TextView
        android:id="@+id/tvFechaNacimientoContador"
        android:layout_width="60dp"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:textAlignment="center"
        android:text="100/100"/>

</LinearLayout>

</android.support.design.widget.CoordinatorLayout>
    
asked by Leonidas 12.11.2018 в 03:58
source

0 answers