Using keyboard with stateAlwaysVisible, after touch any letter its “select” the button, why?

青春壹個敷衍的年華 提交于 2019-12-25 03:48:26

问题


I have only one button in my layout and the activity has nothing. On Manifest it has the android:windowSoftInputMode="stateAlwaysVisible" for the activity, to always show the keyboard.

The problem is that when touch any key on keyboard the only one button is kind selected. Like "highlighted" the entire button in blue.

But I don't want this behavior, how can I avoid it?

Sorry I can not add images because of my reputation...

Below are my codes:

Manifest:

<activity
   android:name=".MainActivityTest"
   android:windowSoftInputMode="stateAlwaysVisible">
</activity>

Activity:

    public class MainActivityTest extends Activity {

       @Override
       protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_main_activity_test);
       }
    }

Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/bt_testButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

</LinearLayout>

回答1:


Add the following attribute to your LinearLayout can avoid this behavior:

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

I have tried and it works well.



来源:https://stackoverflow.com/questions/25050699/using-keyboard-with-statealwaysvisible-after-touch-any-letter-its-select-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!