Android的 - 将焦点设置到一个按钮插件的活动编程的onCreate [英] Android - Set focus to a button widget programmatically onCreate of the activity

查看:107
本文介绍了Android的 - 将焦点设置到一个按钮插件的活动编程的onCreate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以设置一个焦点的一个按钮控件,它躺在我的布局的地方。活动的的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"

这篇关于Android的 - 将焦点设置到一个按钮插件的活动编程的onCreate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆