经过大量搜索,我找到了这个问题的各种解决方案,但是这个解决方案对我不起作用。我使用这个link,但不适合我,我也使用这个link它也没有适合我。请帮我 。我完全被困在这里。
我使用以下代码:来自我称之为对话的活动:
FirstStartDialog dialog=new FirstStartDialog(this);
dialog.show();
那么我的Dialog类就是这样:
public class FirstStartDialog extends AlertDialog{
public FirstStartDialog(final MainWindow mainWindow,
) {
super(mainWindow);
}
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.new_account_dialog);
//getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
editText_registration_username = (EditText) findViewById(R.id.etxt_User_Name);
editText_registration_password = (EditText) findViewById(R.id.etxt_Password);
_btn_registration_next = (Button) findViewById(R.id.btn_registration_next);
_tap_here_registration = (TextView) findViewById(R.id.txt_Tap_Here_Message);
_relative_Main_new_Account = (RelativeLayout) findViewById(R.id.relative_Main_New_Account);
editText_login_username = (EditText) findViewById(R.id.etxt_Existing_User_Name);
editText_login_password = (EditText) findViewById(R.id.etxt_Exiting_User_Password);
_btn_login_next = (Button) findViewById(R.id.btn_login_next);
_tap_here_login = (TextView) findViewById(R.id.txt_Tap_Here_Existing);
_relative_Main_Existing_Account = (RelativeLayout) findViewById(R.id.relative_Main_Existing_Account);
editText_registration_username.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
FirstStartDialog.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
editText_registration_password.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
FirstStartDialog.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
}
}
在xml文件中,我定义了我的EditText:
<EditText
android:id="@+id/etxt_Password"
android:layout_width="210dp"
android:layout_height="22dp"
android:layout_marginTop="5dp"
android:hint="Password"
android:paddingLeft="8dp"
android:textColor="@android:color/black"
android:paddingRight="8dp"
android:textCursorDrawable="@null"
android:gravity="center_vertical"
android:textSize="12sp"
android:layout_below="@+id/etxt_User_Name"
android:layout_centerHorizontal="true"
android:background="@drawable/login_new_account_editbox"
/>
请帮帮我。
答案 0 :(得分:2)
尝试这种方式:
public class FirstStartDialog extends Dialog { Context context; final AlertDialog.Builder alert; public FirstStartDialog(Context p_context) { super(p_context); context = p_context; alert = new AlertDialog.Builder(context); } protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); LayoutInflater inflater = getLayoutInflater(); View container = inflater.inflate(R.layout.new_account_dialog, null); final EditText editText_registration_username = (EditText)container.findViewById(R.id.etxt_User_Name); editText_registration_username .setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { ((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)) .showSoftInput(editText_registration_username, InputMethodManager.SHOW_FORCED); } } }); setContentView(container); } }
如上所述实施对话框,您将打开键盘。