1

多くの検索の後、この質問のさまざまな解決策を見つけましたが、その解決策は私には機能しません。私はこのリンク 使用しますが、私には機能しません。私を助けてください 。私はここで完全に立ち往生しています。

私は次のコードを使用します: そのようなダイアログを呼び出したアクティビティから:

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"
            />

私を助けてください。

4

1 に答える 1

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);
}    }

上記のようにダイアログを実装すると、キーボードが開きます。

于 2013-01-24T05:42:58.673 に答える