ダイアログまたはAlertDialogを拡張して、ダイアログをカスタマイズします
-
21-09-2019 - |
質問
私は、カスタムDialog
を作りたいです。私はそのスタイル好きではないので、私は角の丸い四角形ではなく、鋭い角を持っていると思います。私はAndroidManifest.xml
でのテーマでそれを実装する方法を知っている、例えば、私が使用します:
android:theme="@style/Theme.CustomDialog"
そしてTheme.CustomDialog.xml
ます:
<style name="Theme.CustomDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@drawable/filled_box</item>
<item name="android:windowNoTitle">true</item>
filled_box.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff"/>
<stroke android:width="3dp" color="#ffff8080"/>
<corners android:radius="30dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
私はDialog
またはAlertDialog
を拡張することによって同様の結果を実装する方法を教えてください。
解決
ダイアログコールsuper(context, R.style.CustomDialog);
を拡張するクラスのコンストラクタで、私は、特定のテーマをカスタムダイアログを作成するには、この何回もやった。
しかし、あなただけのダイアログクラスのインスタンスをインスタンス化しようとし、それをDialog dialog = new Dialog(context, R.style.CustomDialog);
ダイアログを拡張する例:
public class MyDialog extends Dialog
{
public MyDialog(final Context context)
{
// Set your theme here
super(context, R.style.MyDialogTheme);
// This is the layout XML file that describes your Dialog layout
this.setContentView(R.layout.myDialogLayout);
}
}
あなたがこのクラスに追加するコードの残りの部分はかなり正確にあなたがActivityクラスで書くと何のようになるだろうされます。
所属していません StackOverflow