【问题标题】:android Custom dialog translucent marginandroid自定义对话框半透明边距
【发布时间】:2015-05-18 20:38:57
【问题描述】:

如何自定义弹出对话框周围半透明区域的外观?也就是说,显示底层活动的区域。

弹出活动正在启动

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

app 是当前活动。

XML 文件的顶层是一个 ScrollView。我试过在那里设置背景,但该设置被忽略了。同样,我尝试调整边距,但这些也被忽略了。 (注意 - 我现在意识到边距仅适用于 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" >

以上,margin和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 确实有所作为 - 它允许原始活动以全亮度显示。然而,其他属性似乎被忽略了。我尝试了这么多设置都没有效果的事实让我相信,要么我错过了一些重要的“lynch pin”设置,要么谷歌硬编码了太多的行为,这些设置无法正常工作。

我可以在我的所有弹出窗口中添加另一个图层,该图层是全屏的,并且按照我想要的方式进行半透明,将真正的对话框放在上面。如果有合适的方法来做我想做的事,我宁愿不做变通方法。

谢谢。

【问题讨论】:

    标签: android dialog themes


    【解决方案1】:

    ScrollView 存在问题,因为它从 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>
    

    【讨论】:

    • “ScrollView 有问题”是什么意思?
    • 关于边距,在你的情况下。
    • 对。边距应仅适用于 LinearLayout。好吧,那么利润就是手头问题的红鲱鱼。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多