0

ダイアログボックスがありますが、背景画像が不明な場合があります。その画像を削除するにはどうすればよいですか。案内してください。

ここに画像の説明を入力してください

4

2 に答える 2

2

Dialog Classを拡張し、ダイアログ用のxmlファイルを次のように作成する必要があります。

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Do you Want to bookmark?" 
        android:gravity="center"/>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button_no"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="No" />

        <Button
            android:id="@+id/button_yes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Yes" />

    </LinearLayout>

</LinearLayout>

もちろん、いくつかのカスタマイズを行うことができます

カスタムダイアログクラスの場合、次のように実行できます

public class CustomizeDialog extends Dialog implements OnClickListener {
 Button okButton;

 public CustomizeDialog(Context context) {
  super(context);

  /** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
  requestWindowFeature(Window.FEATURE_NO_TITLE);


  setContentView(R.layout.main);
  yesButton = (Button) findViewById(R.id.button_yes);
  yesButton.setOnClickListener(this);

  noButton = (Button) findViewById(R.id.button_no);
  noButton.setOnClickListener(this);

 }

 @Override
 public void onClick(View v) {
        switch(v.getId()){

        case R.id.button_yes: 
             dismiss();
             //doSomething
             break;
            case R.id.button_no:
            dismiss();
            //doSomethingElse
            break;

 }

}

これが、これらの背景ボックスが表示される理由を理解するためにコードを投稿する必要があるのに役立つことを願っていますが、私が述べたように行動することで問題が解決するはずです

于 2012-05-08T09:22:57.107 に答える
1

これはおそらく、標準を使用しAlertDialog、コンテンツ ビュー + タイトルなしを設定しているためです (タイトルを設定していなくても、そのスペースはダイアログに残ります)。

代わりにクラスを拡張し、Dialog必要に応じてダイアログを作成してください。また、独自の背景を使用したい場合は、拡張およびオーバーライドDialogするテーマを実装します。Theme.Dialog

<item name="android:windowBackground">@android:drawable/panel_background</item>

独自のドローアブルで。

于 2012-05-08T08:58:00.510 に答える