繁体   English   中英

EditText 焦点在 android studio 中不起作用,我想在 edittext 焦点改变时隐藏一个 textview,怎么办?

[英]EditText focus is not working in android studio, i want to hide a textview when focus change in edittext, how to do this?

EditText 作为 ChangeContact

EditText 焦点在 android studio 中不起作用,我想在 edittext 焦点改变时隐藏一个 textview,怎么办?

       ChangeContact.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if (!hasFocus) {
                        Toast.makeText(mContext, "focus loosed", Toast.LENGTH_LONG).show();
                      
                    } else {
                        Toast.makeText(mContext, "focused", Toast.LENGTH_LONG).show();
                        bookLinear.setVisibility(View.GONE);
                    }
                }
            });

我在 XMl 文件中编辑文本

  <EditText
                    android:id="@+id/etChangeAddress"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="6dp"
                    android:layout_marginBottom="8dp"
                    android:background="@drawable/shape_transparent"
                    android:ems="10"
                    android:focusable="true"
                    android:focusableInTouchMode="true"
                    android:gravity="center"
                    android:hint="Address"
                    android:inputType="textPersonName"
                    android:padding="5dp"
                    app:layout_constraintBottom_toTopOf="@+id/etChangeNumber"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent" />

但我看不到 Toast

请帮忙....

您是否尝试过使用 ChangeContact?

 android:focusable="true"
 android:focusableInTouchMode="true"

还有 ChangeContact.requestFocus()?

在我的例子中,我无法关注焦点更改事件,因为我忘记删除setContentView() function 并将其用于绑定初始化,如下所示:

 setContentView(R.layout.activity_main)
    
 binding = ActivityMainBinding.inflate(layoutInflater, null, false)

最终我也明白绑定初始化也是不正确的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM