2013-01-04 105 views
0

我的問題是,我不希望顯示透明對話框中全屏幕下方 是我使用的代碼對話框全屏

dialog = new Dialog(this, R.style.CustomDialogTheme); 
    dialog.setContentView(R.layout.enterjoinseecode_dialog); 

CustomDialog主題

<style name="CustomDialogTheme" parent="@android:style/Theme.Translucent.NoTitleBar"> 
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowIsFloating">true</item> 
    <item name="android:windowFullscreen">false</item> 
</style> 

請一些人幫助我我出錯的地方

+0

您可以請發佈錯誤或不必要的行爲,你通過運行你的代碼? –

回答

0

試試這個。創建您的視圖Dialog像下面一樣。

<RelativeLayout 
    android:layout_width="450dp" 
    android:layout_height="250dp" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:orientation="vertical" > 

// Here you can add your component. 

</RelativeLayout> 

並設置你的對話框這個視圖。

dialog = new Dialog(this, R.style.CustomDialogTheme); 
dialog.setContentView(R.layout.enterjoinseecode_dialog); 

就是這樣,希望這會對你有幫助。

+0

thanks for reply.dont想要硬編碼任何值 – Manju

+0

你想在對話框中顯示什麼? – Akshay

0

創建一個透明背景的活動,併爲特定活動定義主題,這樣

<activity android:theme="@android:style/Theme.Dialog" /> 

而且,如果你還希望該活動是完全一樣的對話框,那麼你也可以使用這個

android:excludeFromRecents="true" 

將其從最近的應用程序列表中刪除。

+0

感謝您的回覆,但我只想在對話框中顯示。不在活動中 – Manju

+0

如果你使用這個,那麼你的活動就像一個對話框。試試看。這與對話框完全一樣。 – Antrromet

+0

感謝您的意見。但不希望在單獨的活動中添加與對話相關的所有事件。 – Manju

0

一些如何通過以下步驟得到與出全屏透明效果的對話框

無需定義風格的「CustomDialogTheme」需要傳遞的構造函數中的主題參數作爲android.R.style.Theme_Translucent_NoTitleBar

並與充氣XML只是用背景作爲機器人:背景=「#29000000」使它透明效果和layout_gravity屬性來定位對話框

如果我使用上述式CustomDialogTheme某種程度上其示出了作爲一個窗口,而不是因爲我應用了對話直接主題,以顯示作爲對話框(而不是全屏),並使其在xml透明效果我設置屬性背景