質問

私は、カスタム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);

のようなテーマのIDを渡すことができます

ダイアログを拡張する例:

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クラスで書くと何のようになるだろうされます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top