有很多帖子涉及这个话题.我想我应该问这个简单的问题,希望澄清一下.
我无法将焦点设置在按钮上.我知道我可能会错过一些基本的东西 这是简单的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:focusable="true" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
以下是onCreate()中的简单代码:
Button button = (Button)findViewById(R.id.button1);
button.setFocusable(true);
button.requestFocus();
button.setText("Debug"); //Just to show the code here has been executed
Run Code Online (Sandbox Code Playgroud)
它根本不起作用(即按钮没有得到焦点).
任何纠正我的错误或误解将不胜感激.