私たちのAboutスクリーンをアンドロイドのポップアップ/ダイアログとして作成しています。このダイアログにボタン(OKまたはCANCEL)を追加したいと思います。どうやってやるの ?Androidで警告ダイアログを作成し、ボタンを追加してダイアログを閉じる(ポップアップ)
これは私のレイアウトファイル
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:id="@+id/popup"
android:layout_height="wrap_content"
android:background="#E3C39D"
android:orientation="vertical"
android:padding="0dp">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="About Us.."
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:textSize="20dp"
android:textColor="#ffffff"
style="@style/TextShadow"/>
<View
android:id="@+id/SplitLine_hor1"
android:layout_width="match_parent"
android:layout_height= "1dp"
android:background="#000" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:text="Hello ! I want to put a button below with label 'OK' and Click on this OK button the popup should be close. Thank you !" />
</LinearLayout>
であり、以下に私がalert.setPositiveButton("OK",null);
かalert.setInverseBackgroundForced(true);
を使用してい
public void AboutUsDialog(){
final AlertDialog.Builder alert;
alert = new AlertDialog.Builder(this);
LayoutInflater inflater = MainActivity.this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.activity_about_us, null);
alert.setView(dialogView);
alert.show();
alert.setPositiveButton("OK",null);
//alert.setInverseBackgroundForced(true);
}
ダイアログボックスの機能です。しかし、私はダイアログに何のボタンも表示されませんでした。
画面上の任意の場所をタッチすると、ダイアログが消えます。私はOKボタンだけでポップアップを閉じたいです。
ありがとうございます!
出力
uは上記のいずれかを試してくださいました – Priyanka
@AbhishekTandonは(偽) '' dialog.setCancelable画面のクリックでダイアログ解雇を無効に設定します。 – SripadRaj