Android - NestedScrollView中的EditText立即失去焦点

时间:2016-02-02 10:11:34

标签: android android-edittext android-softkeyboard android-nestedscrollview

我有一个EditText包装在RecyclerView下面的TextInputLayout中,两者都在NestedScrollView中。

这是我的布局有点简化:

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

在我的清单中,我在活动中有这个:

android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"

我的问题是:

EditText不会将重点放在触控上。我触摸它,它下面的条似乎应该,但然后立即消失,如果它只是失去了焦点:没有提示上升,没有它下面的酒吧:没有。当然没有键盘出现。

任何想法都非常受欢迎。在此先感谢您的帮助。

修改: 我的问题被标记为此问题的可能重复EditText Loses Focus on Click 不是。我尝试过这些解决方案,它不起作用,键盘根本没有显示出来。

**编辑:**

这是我的自定义编辑文本代码:

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

0 个答案:

没有答案
相关问题