1


EditText の ContextMenu のスタイルに問題があります。

新しいダイアログを作成しました:

Dialog newServerDialog = new Dialog(getContext(), R.style.CustomDialogStyleServerDetails);

newServerDialog.setContentView(newServerDialogLayout);
newServerDialog.setTitle(R.string.server_details_new_title_text);
newServerDialog.getWindow().setLayout(
    android.view.ViewGroup.LayoutParams.FILL_PARENT,
    android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
newServerDialog.setCancelable(true);

CustomDialogStyleServerDetailsスタイルは次のとおりです。

<style name="CustomDialogStyleServerDetails" parent="@android:style/Theme.Dialog">
    <item name="android:background">@drawable/server_details_background_repeat</item>
    <item name="android:windowTitleStyle">@style/DialogWindowTitle</item>
</style>

そしてDialogWindowTitleスタイル

<style name="DialogWindowTitle">
    <item name="android:maxLines">1</item>
    <item name="android:scrollHorizontally">true</item>
    <item name="android:textAppearance">@style/customDialogTextAppearance</item>
    <item name="android:gravity">center_horizontal|center_vertical</item>
    <item name="android:background">@drawable/server_details_title_background_repeat</item>
</style>

ダイアログは私が望むように見えます: (申し訳ありませんが、まだ画像を投稿できません)

Dialog.png

しかし、EditText の ContextMenu は私のダイアログからスタイルを取ります

EditText の ContextMenu.png

デフォルトのスタイルを ContextMenu に設定する方法はありますか?
この問題の修正は見つかりませんでした。
すべての助けに感謝します!
ありがとうございました。

EDIT:私にとっての解決策:Dialogを拡張するカスタムクラス(DialogServerと呼ばれる)を作成します。
編集#2:いいえ、それは正しい解決策ではないようです。

私はこのコンストラクタを試しました:

public DialogServer(Context context, int theme)

そして問題は残る

このコンストラクターでは:

public DialogServer(Context context)

contextmenu のスタイルは問題ありませんが、ダイアログのスタイルはなくなりました。

4

1 に答える 1

2

カスタム テーマ ラッパーを使用してみる

 ContextThemeWrapper mTheme = new ContextThemeWrapper(this,
        R.style.CustomDialogStyleServerDetails);

コードスニペットは次のとおりです:-

mInflater = (LayoutInflater) getBaseContext().getSystemService(
        LAYOUT_INFLATER_SERVICE);

ContextThemeWrapper mTheme = new ContextThemeWrapper(this,
        R.style.CustomDialogStyleServerDetails);

mView = mInflater.inflate(R.layout.YOUR_XML_LAYOUT_FILE, null);


mDialog = new Dialog(mTheme);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(this.mView);
mDialog.show();

説明がお役に立てば幸いです....

于 2012-10-04T07:51:48.027 に答える