我对 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>
对话框看起来像我想要的:(抱歉,我还不能发布图片)
但是 EditText 的上下文菜单采用了我的对话框的样式
有什么办法,如何将默认样式设置为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/