use*_*239 89 java android focus
目前,我有一个包含a Button,a TextView和an 的布局EditText.当显示布局时,焦点将自动放在EditText,这将触发键盘显示在Android手机上.这不是我想要的.有什么方法可以在TextView显示布局时设置焦点或什么都没有?
Cha*_*dup 18
这有效:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Run Code Online (Sandbox Code Playgroud)
要设置焦点,请使用处理程序延迟requestFocus().
private Handler mHandler= new Handler();
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout mainVw = (LinearLayout) findViewById(R.id.main_layout);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
EditText edit = new EditText(this);
edit.setLayoutParams(params);
mainVw.addView(edit);
TextView titleTv = new TextView(this);
titleTv.setText("test");
titleTv.setLayoutParams(params);
mainVw.addView(titleTv);
mHandler.post(
new Runnable()
{
public void run()
{
titleTv.requestFocus();
}
}
);
}
}
Run Code Online (Sandbox Code Playgroud)
您可以尝试隐藏键盘.像这样的东西:
InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
149899 次 |
| 最近记录: |