I included the LinearLayout between the Coordinator
and the TextInputLayout
, moved the ImageButton
to the LinearLayout
and accommodated the layout.
To the button out there you should wrapearlo in a FrameLayout
and give it a specific size.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100">
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="90"
app:counterEnabled="true">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Fecha de Nacimiento"/>
</android.support.design.widget.TextInputLayout>
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="10"
android:layout_gravity="center"/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
And it looks like this:
II) Another option is to use drawableRight
of TextInputEditText
.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.TextInputLayout
android:id="@+id/ti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:counterEnabled="true">
<android.support.design.widget.TextInputEditText
android:id="@+id/tied"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/calendario"
android:drawablePadding="5dp"
android:hint="Fecha de Nacimiento"/>
</android.support.design.widget.TextInputLayout>
</android.support.design.widget.CoordinatorLayout>
And in onCreate()
of Activity
tied = findViewById(R.id.tied);
tied.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_RIGHT = 2;
if(event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_POINTER_UP) {
if(event.getRawX() >= (tied.getRight() - tied.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
Log.d(TAG, "Click en imagen"); // Lo que acciona el click
return true;
}
}
return false;
}
});
Note: The image is 30 x 30 px. To change the size you have to change the size of the PNG.