0

私は xml ファイル (ダイアログ) を作成し、LayoutInflater でそれを縮小したかったのですが、常に私の画面とほぼ同じ大きさです。コードは次のとおりです。

protected Dialog onCreateDialog(int id) {
     switch(id) {
     case NICKNAME_DIALOG_ID:
         LayoutInflater inflater = (LayoutInflater) 
                 getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             final View layout = inflater.inflate(R.layout.nickname_dialog, 
                 (ViewGroup) findViewById(R.id.linearLayout_root));
             final EditText nickname =   
                (EditText)findViewById(R.id.editText_nickname);   

            AlertDialog.Builder nicknameBuilder = new AlertDialog.Builder(this);
            nicknameBuilder.setView(layout);
            nicknameBuilder.setTitle(R.string.nicname_dialog_title);

            nicknameBuilder.setNegativeButton(R.string.nickname_dialog_cancel, 
                new DialogInterface.OnClickListener() {
                @SuppressWarnings("deprecation")
        public void onClick(DialogInterface dialog, int whichButton) {                      
                    SettingsActivity.this.removeDialog(NICKNAME_DIALOG_ID);
                }
            });

            nicknameBuilder.setPositiveButton(R.string.nickname_dialog_ok, 
                new DialogInterface.OnClickListener() {
                @SuppressWarnings("deprecation")
            public void onClick(DialogInterface dialog, int which) {
                    String text = nickname.getText().toString();
                    Editor editor = m_GameSettings.edit();
                    editor.putString(VolimHrvatsku.GAME_PREFERENCES_NICKNAME,
                            text);
                    editor.commit();
                    SettingsActivity.this.removeDialog(NICKNAME_DIALOG_ID);
                }
            });
            AlertDialog nicknameDialog = nicknameBuilder.create();
            return nicknameDialog;

     }

    return null;

}

ニックネーム ダイアログ xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sahovnica"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView_enter_nickname"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/settings_enter_nick"
    android:textColor="@color/dark_grey"
    android:textSize="@dimen/scores_text_dim"
    android:textStyle="bold" />

<EditText
    android:id="@+id/editText_nickname"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" >

    <requestFocus />
</EditText>

<RelativeLayout
    android:id="@+id/relativeLayout_nickname"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

</RelativeLayout>

</LinearLayout>

電子メール ダイアログ xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout_email"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sahovnica"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView_body"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/email_dialog_text"
    android:textColor="@color/dark_grey"
    android:textSize="@dimen/scores_text_dim"
    android:textStyle="bold" />

<EditText
    android:id="@+id/editText_body"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:ems="10" >

    <requestFocus />
</EditText>

<RelativeLayout
    android:id="@+id/relativeLayout_email"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

</RelativeLayout>

</LinearLayout>

ところで、AlertDialog の [はい] ボタンと [いいえ] ボタンの外観を変更できるかどうかお尋ねしたいと思いますか? 前もって感謝します...

4

1 に答える 1

0

レイアウトemaildialog.xmlの幅と高さを行うwrap_content

私はそう思います、これはあなたを助けるかもしれません。

于 2013-09-20T10:42:33.157 に答える