2015-05-18 59 views
2

如何定製圍繞彈出對話框的半透明區域的外觀?也就是說,顯示潛在活動的區域。android自定義對話框半透明邊距

彈出活動正在開始

Intent intent = new Intent (app, MyPopup.class); 
app.startActivityForResult (intent, requestCode); 

這裏app是當前活動。

XML文件的頂層是一個ScrollView。我試着在那裏設置背景,但設置被忽略。另外,我嘗試調整邊距,但也忽略了這些邊距。 (NB - 我現在認識到,利潤只適用於LinearLayout中;忽略的問題,請。)例如:

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="20dp" 
    android:maxWidth="200dp" > 

以上,保證金和maxWidth被忽略。

而且,我試着建立一個自定義樣式:

<style name="PopupTheme" parent="android:style/Theme.Dialog"> 
    <item name="android:background">#FFF2F2F2</item> 
    <item name="android:textColor">#FF000000</item> 
    <item name="android:windowNoTitle">true</item>" 
    <item name="android:backgroundDimEnabled">false</item> 
    <item name="android:windowIsTranslucent">false</item> 
    <item name="android:windowBackground">@drawable/dialog_background</item> 
</style> 

在這種風格,backgroundDimEnabled確實有差別 - 它允許始發胡亞蓉在全亮度顯示。但其他屬性似乎被忽略。事實上,我嘗試過的很多設置都沒有效果,這讓我相信,我錯過了一些重要的「私人密碼」設置,或者谷歌硬編碼了太多的行爲以使這些設置正常工作。

我可以添加另一層我所有的彈出窗口,在該層是全屏幕和不透光的方式我想,他有真正的對話放在最重要的是。如果有正確的方法來做我想做的事情,我寧願不採取解決方法。

謝謝。

回答

0

有一個與滾動型問題,因爲它從延伸的FrameLayout裏,因爲這不能適用利潤率它。我可以做的一點是在ScrollView中創建一個LinearLayout併爲其應用邊距。

是這樣的:

<ScrollView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="top" 
        android:layout_marginTop="30dp" 
        android:orientation="vertical" > 
</ScrollView> 
+0

你是什麼意思「有一個與滾動型有問題」? –

+0

關於利潤率,在你的情況。 –

+0

對。邊距應該只適用於LinearLayout。那麼,利潤率對於手頭的問題是一種衝擊。 –