4

以下の回答では適切な解決策が得られなかったため、必要なものをよりよく理解するために質問を編集しています。したがって、私がしなければならないことは、下部にニュートラル ボタンがあるカスタム アラート ダイアログを作成することです。これがどのように見えるべきかの例です:

このようなダイアログを作成する必要があります

これまで、xml を使用してアクティビティを に変更するカスタム ダイアログを使用していandroid:theme="@android:style/Theme.Holo.Light.Dialog"たので、同じようなルック アンド フィールを得ることができます。ここに私のxmlコードがあります:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dialog"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/login_prompt_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:text="@string/login_prompt_rewards_header"
        android:textSize="17sp"
        android:textStyle="bold" >
    </TextView>

    <TextView
        android:id="@+id/login_prompt_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_prompt_header"
        android:layout_marginTop="5dp"
        android:gravity="center_vertical|center_horizontal"
        android:paddingLeft="18dp"
        android:paddingRight="18dp"
        android:text="@string/login_prompt_rewards_text"
        android:textSize="15sp" >
    </TextView>

    <Button
        android:id="@+id/log_in"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_prompt_text"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="15dp"
        android:background="@drawable/log_in"
        android:contentDescription="@string/none" >
    </Button>

    <Button
        android:id="@+id/create_account"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/log_in"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:background="@drawable/create_account"
        android:contentDescription="@string/none" >
    </Button>

</RelativeLayout>

上記のレイアウトにより、次の結果が得られます。

今まで実装

私が直面している問題は次のとおりです:カスタムダイアログでニュートラルボタンを設定する方法は? 私はこれについて何の考えも得ていません。私の質問に疑問がある場合、または言語を理解できない場合は、コメントを残してください。もう一度明確なアイデアを提供できるようにします. 助けていただければ幸いです。

4

3 に答える 3

12

次のようなカスタム アラート ダイアログを作成します。

public void messageDialog(String title, String message, final Context activity) {

        final Dialog myDialog = new Dialog(activity);
        myDialog.setContentView(R.layout.messagescreen);
        myDialog.setTitle(title);
        myDialog.setCancelable(false);

        TextView text = (TextView) myDialog.findViewById(R.id.bidmessage);
        text.setMovementMethod(ScrollingMovementMethod.getInstance());
        text.setText(message);

        Button login = (Button) myDialog.findViewById(R.id.buttonlogin);
        login.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                myDialog.dismiss();


            }
        });

        Button createAccount= (Button) myDialog.findViewById(R.id.buttoncreateaccount);
        createAccount.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                myDialog.dismiss();


            }
        });


        myDialog.show();

    }

画像に表示されているように、カスタム作成されたレイアウトはどこにR.layout.messagescreenありますか。これを試してみて、問題が発生した場合はお知らせください。

于 2013-02-14T12:41:06.787 に答える
0

これを簡単に設定できます:

dialog.setNeutralButton("skip", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //Your code
            }
        });
于 2016-07-06T10:39:25.727 に答える