android - 如何将默认的 ContextMenu 样式设置为 EditText?

标签 android android-dialog android-theme android-contextmenu


我对 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 的上下文菜单采用了我的对话框的样式

EditText's ContextMenu.png

有什么办法,如何将默认样式设置为ContextMenu?
我没有找到解决此问题的方法。
我们将不胜感激!
谢谢。

编辑:我的解决方案:创建一个扩展 Dialog 的自定义类(称为 DialogServer)。
编辑 #2:不,看起来这不是正确的解决方案。

我试过这个构造函数:

public DialogServer(Context context, int theme)

问题依旧

使用这个构造函数:

public DialogServer(Context context)

contextmenu的样式没问题,但是dialog的样式没了。

最佳答案

尝试使用自定义主题包装器

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

代码 fragment 是:-

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();

希望解释有用....

关于android - 如何将默认的 ContextMenu 样式设置为 EditText?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12566231/

相关文章:

android - 从 Twitter 到我的应用程序的深层链接 - 不工作

java - 如何在 Android WebView 中仅显示网站的一部分

Android/如何最好地定义主题/值

android - onCreate() 方法是如何运行的?

c# - Xamarin.Android - 如何实现通用图像加载器库中使用的回调

android - 如何在android中显示全屏 fragment Activity ?

Android:在容器中心显示自定义对话框

android - 在 AlertDialog.Builder 中格式化文本

android - Spinner 默认主题到 EditText android

android - Holo.Light.DarkActionBar ActionBar 的默认十六进制颜色是什么