私のAlertDialogでは、ポジティブボタンとネガティブボタンが「接続」されています。私は彼らの間にギャップがあるはずだと確信しています。誰かがなぜこれが起こっているのか教えてもらえますか?私はどんなコードを提供してもうれしいです。 Here is what my AlertDialog looks like.2つのAlertDialogボタンにギャップがないのはなぜですか?
私は、MainActivityでは(私はそれが必要だとは思わないので、そのXMLコードを投稿しますが、私に知らせません。)本体のカスタムビューだけでなく、私のAlertDialogのタイトルを持っています私のカスタムタイトルとボディビューを膨張させ、setPositive()とsetNegative()をオーバーライドすると、onShow()を使用してボタンの色をカスタマイズします。
ご迷惑をおかけして申し訳ありませんが、助けていただければ幸いです。ここに私のMainActivityは次のとおりです。
public void openPrompt(View view){
//builds and opens custom view with prompt.XML
LayoutInflater layoutInflater = LayoutInflater.from(MainActivity.this);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
EditText input = (EditText)promptView.findViewById(R.id.userInput);
builder.setCancelable(true).setView(R.layout.customdialoglayout)
.setNegativeButton("One", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"CANCEL clicked",Toast.LENGTH_SHORT).show();
}
})
.setPositiveButton("Two", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"SET clicked",Toast.LENGTH_SHORT).show();
}
});
//set title with custom XML layout view
LayoutInflater inflater = getLayoutInflater();
View titleView = inflater.inflate(R.layout.cutomtitlebar,null);
builder.setCustomTitle(titleView);
AlertDialog ad = builder.create();
//change colors of background and buttons
ad.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Context context = MainActivity.this;
Window view = ((AlertDialog)dialog).getWindow();
view.setBackgroundDrawableResource(R.color.colorPrompt);
Button negButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
negButton.setBackgroundColor(context.getResources().getColor(R.color.colorPromptButton));
negButton.setTextColor(context.getResources().getColor(R.color.colorPromptButtonText));
Button posButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
posButton.setBackgroundColor(context.getResources().getColor(R.color.colorPromptButton));
posButton.setTextColor(context.getResources().getColor(R.color.colorPromptButtonText));
}
});
ad.show();
}
EDITここで私は()setviewコマンドを使用私のXMLです:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="CUSTOM TEXT"
android:id="@+id/textView3"
android:layout_gravity="center"/>
あなたにレイアウトスペースを追加することができますので、layout.xmlをご覧ください。 – HCarrasko
あなたの質問にAndroidスタジオは何も得られませんでした。関連するタグのみを使用してください。 –