Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
NestedScrollView中的Android-EditText立即失去焦点_Android_Android Edittext_Android Softkeyboard_Android Nestedscrollview - Fatal编程技术网

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

NestedScrollView中的Android-EditText立即失去焦点,android,android-edittext,android-softkeyboard,android-nestedscrollview,Android,Android Edittext,Android Softkeyboard,Android Nestedscrollview,我在RecyclerView下面的TextInputLayout中包装了一个EditText,两者都在NestedScrollView中 这是我的布局有点简化: <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"

我在RecyclerView下面的TextInputLayout中包装了一个EditText,两者都在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>
我的问题是:

编辑文本不会将焦点保持在触摸上。我触摸它,它下面的条看起来像它应该的,但是如果它只是失去了焦点,就立刻消失了:没有提示向上,下面没有条:什么都没有。当然没有键盘出现

任何想法都是非常受欢迎的。提前感谢你的帮助

编辑: 我的问题可能与这个问题重复 不是。我尝试过这些解决方案,但都不起作用,键盘也根本不显示

**编辑:**

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

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

做一个Durya!!!根据高伊的回答,已经试过了。它不会改变任何东西。我看到你的编辑文本是自定义的。你可以把它的代码贴出来吗?也许解决办法就在那里。您是否尝试过使用标准的EditText?请避免在scrollingview中使用listview或recyclerview。您的第一个线性布局没有方向。尝试用RelativeLayout替换NestedScrollView,删除第一个LinearLayout,并将RecyclerView放在第二个LinearLayout的顶部,后者将位于RelativeLayout的底部。
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();
        }
    }
}