I have an EditText wrapped in a TextInputLayout below a RecyclerView, both inside a NestedScrollView.
Here is my layout a bit simplified :
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:layout_marginBottom="?attr/actionBarSize"
android:background="@android:color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Stuff -->
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="LinearLayoutManager"
tools:listitem="@layout/list_item_comment_empty"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingEnd="@dimen/global_horizontal_padding"
android:paddingRight="@dimen/global_horizontal_padding"
android:textColorHint="@color/light_green_color">
<custom.FontEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:hint="@string/your_comment_here"
android:textColor="@android:color/black"
custom:fontName="lato"
custom:fontStyle="regular"/>
</android.support.design.widget.TextInputLayout>
<ImageButton
style="@style/OrangeButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/send"
android:padding="@dimen/global_vertical_padding"
android:src="@drawable/ic_send"/>
</LinearLayout>
In my Manifest I have this on the activity :
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"
My problem is :
The EditText won't keep the focus on touch. I touch it, the bar below it appears like it should, but then immediately disapear like if it just lost the focus : no Hint going up, no bar below it : nothing. And of course no Keyboard showing up.
Any idea is very welcome. Thanks in advance for your help.
Edit : My question has been marked as a possible duplicate of this one EditText Loses Focus on Click It's not. I have tried those solutions, it doesn't work, and the Keyboard doesn't shows up at all.
**Edit : **
Here my custom Edit Text code :
public class FontEditText extends EditText {
private int mFontName;
private int mFontStyle;
public FontEditText(Context context) {
super(context);
init(context, null);
}
public FontEditText(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public FontEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public FontEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.FontViewAttributes,
0, 0);
try {
mFontName = a.getInteger(R.styleable.FontViewAttributes_fontName, 3);
mFontStyle = a.getInteger(R.styleable.FontViewAttributes_fontStyle, 3);
} finally {
a.recycle();
}
String fontName = "";
switch (mFontName) {
case 0:
switch (mFontStyle) {
case 0:
fontName = "lato_bold.ttf";
break;
case 1:
fontName = "lato_italic.ttf";
break;
case 2:
fontName = "lato_light.ttf";
break;
case 3:
fontName = "lato_regular.ttf";
break;
case 4:
fontName = "lato_thin.ttf";
break;
default :
fontName = "lato_regular.ttf";
break;
}
break;
case 1:
switch (mFontStyle) {
case 0:
fontName = "notoSerif_bold.ttf";
break;
case 3:
fontName = "notoSerif_regular.ttf";
break;
default :
fontName = "notoSerif_regular.ttf";
break;
}
break;
}
try {
setTypeface(Typeface.createFromAsset(context.getAssets(), Consts.FONT_PATH_PREFIX + fontName));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}