2012-09-24 104 views
1


我對EditText的ContextMenu的風格有問題。

我創造了新的對話:如何將默認的ContextMenu樣式設置爲EditText?

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

有什麼辦法,如何默認樣式設置爲文本菜單?
我沒有發現此問題的任何修復程序。
所有幫助將不勝感激!
謝謝。

編輯:我的解決方案:創建一個擴展Dialog的自定義類(稱爲DialogServer)。
編輯#2:不,看起來不是正確的解決方案。

我嘗試這樣的構造:

public DialogServer(Context context, int theme) 

和問題依然存在

採用這種構造:

public DialogServer(Context context) 

的ContextMenu的風格是好的,但該對話框的風格了。

回答

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

希望的解釋是有用的....

+0

感謝您的幫助,但它不工作。 ContextMenu的風格仍然是錯誤的。我試圖創建擴展Dialog的自定義Dialog類,但問題仍然存在(請參閱編輯的問題)。 –

相關問題