上の図のようなダイアログボックスを作成する方法を知っている人はいますか?
- 丸みを帯びた角。
- 透明な背景。
- タイトル、ボタン、ボーダーなし。
- フェードイン -- 5 秒間の遅延 -- フェードアウト。
*トースト、ポップアップ ウィンドウ、ダイアログ、アラート ダイアログを見てきましたが、上記に最も適しているのはどれですか? :)
いくつかのコードスニペットを提供できればいいのですが、私はアンドロイドにかなり慣れていません:)
上の図のようなダイアログボックスを作成する方法を知っている人はいますか?
*トースト、ポップアップ ウィンドウ、ダイアログ、アラート ダイアログを見てきましたが、上記に最も適しているのはどれですか? :)
いくつかのコードスニペットを提供できればいいのですが、私はアンドロイドにかなり慣れていません:)
カスタム ダイアログについては、http: //www.c-sharpcorner.com/UploadFile/2fd686/androd-dialogs/ を確認してください。
private void createCustomDialog(){
//Create a dialog object
final Dialog dialog = new Dialog(MainActivity.this);
//Set its layout
dialog.setContentView(R.layout.custom_dialog_layout);
//Set the title
dialog.setTitle("This is custom layout");
//Make it cancelable
dialog.setCancelable(true);
//We need to dismiss the dialog so we add a listener to the ok button
dialog.findViewById(R.id.okButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
dialog.show();
}
}
暗いアルファ背景の場合、ドローアブルを作成できます。以下のコードは、角が丸い半透明の背景を提供します。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#AA000000"
android:endColor="#AA000000"
android:angle="-90"
android:type="linear"
/>
<corners android:radius="10dp" />
</shape>
</item>
</layer-list>
自動非表示部分に使用できます
Animation anim = new AlphaAnimation(1,0);
anim.setDuration(300);
anim.setStartOffset(5000);
anim.setInterpolator(new LinearInterpolator());
anim.setFillAfter(false);
myView.startAnimation(anim);
これを試して
目的のコンテンツで XML を作成し、透明な画像をそれに設定します
私はあなたに画像を提供しています、これを使用してください
そしてその
タイプ PopupWindow のフィールドを宣言します。PopupWindow ポップアップ;
ここでレイアウトを膨らませます
View v = inflatter.inflate(R.layout.yourlayout, null);
レイアウトをポップアップウィンドウに設定します
v1.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int height1 = v1.getMeasuredHeight();
popup= new PopupWindow(v, (int) (width * 0.8), height1, true);
popup.showAtLocation(mainlayout, Gravity.CENTER, 0, 0);
mainlayout
あなたのアクティビティ ビュー グループは
これは、アプリで使用したコードです。
例私は自分のアプリでこのようなものを使用しました
まったく問題ありません。遅延とフェードを使用して 9 番目のパッチ ドローアブルを作成し、ダイアログの背景として配置するだけです。