是否可以设置一个焦点的一个按钮控件,它躺在我的布局的地方。活动的的onCreate
我的控制/重点应该放在该按钮编程。
Is it possible to set a focus to a button widget which lies somewhere down in my layout. onCreate
of the activity my control/focus should be on that button programmatically.
是的这是可能的。
Button myBtn = (Button)findViewById(R.id.myButtonId);
myBtn.requestFocus();
或XML
<Button ...><requestFocus /></Button>
重要提示: Button控件必须是可聚焦
的和的 focusableInTouchMode
。大多数部件是可聚焦
而不是 focusableInTouchMode
默认情况下。因此,请务必将它设置在code
Important Note: The button widget needs to be focusable
and focusableInTouchMode
. Most widgets are focusable
but not focusableInTouchMode
by default. So make sure to either set it in code
myBtn.setFocusableInTouchMode(true);
或XML
android:focusableInTouchMode="true"