代码之家  ›  专栏  ›  技术社区  ›  Codejoy

在不褪色背景的情况下调用android dialog

  •  32
  • Codejoy  · 技术社区  · 14 年前

    我有一个很好的对话框视图,我将UserInputDialog类设置为:

        <LinearLayout android:id="@+id/LinearLayout01" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:orientation="vertical"
        xmlns:android="http://schemas.android.com/apk/res/android">
    
            <TextView
            android:id="@+id/nameMessage"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="What is your name Captain?"
            >
            </TextView>
            <EditText
            android:id="@+id/nameEditText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            >
            </EditText>
        <LinearLayout android:id="@+id/LinearLayout02" android:layout_width="fill_parent" android:layout_height="wrap_content" 
            android:layout_gravity="center_horizontal">
        <Button
            android:id="@+id/okButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="OK">
            </Button>
            <Button android:id="@+id/cancelButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cancel">
            </Button>               
        </LinearLayout>
    </LinearLayout>
    

    我希望我的对话框出现,但背景不会淡出。这有可能吗?因为调用此对话框的视图有一个neato背景,我希望显示为对话框的背景。

    我在网上找到这个:

    <style name="doNotDim" parent="@android:style/Theme.Dialog">
        <item name="android:backgroundDimAmount">0</item>
    </style >
    

    但不确定如何将其应用于我的对话?我有个班级叫 public class UserInputDialog extends Dialog implements OnClickListener . 它将其内容视图设置为上述布局。

    我想我做得很好,只是不知道如何添加那个样式,这样我就不会褪色的背景。

    第二个问题:你能通过使用主题在你的对话中获得新的外观吗(比如在对话中显示一个图片或图标)?

    4 回复  |  直到 9 年前
        1
  •  30
  •   Robby Pond    14 年前

    创建res/values/styles.xml文件并将其添加到其中。

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
      <style name="Theme.DoNotDim" parent="android:Theme">
        <item name="android:backgroundDimEnabled">false</item>
      </style>
    </resources>
    

    并将主题应用于您的活动。

    <activity android:name=".SampleActivity" android:theme="@style/Theme.DoNotDim">
    
        2
  •  158
  •   Peter Lang    13 年前

    您还可以使用以下代码删除“暗淡”效果:

    dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    
        3
  •  5
  •   John P.    12 年前

    创建自定义样式并将其放置在“值”文件夹中

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
      <style name="YourCustomStyle" parent="android:Theme">
        <item name="android:backgroundDimEnabled">false</item>
      </style>
    </resources> 
    

    要将样式设置为单个对话框,可以使用

    Dialog dialog = new Dialog(context, R.style.YourCustomStyle);
    
        4
  •  1
  •   activesince93 RexSplode    9 年前

    用于显示类似对话框 特雷卡勒 这样做:

    styles.xml 文件。

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
      <style name="myBackgroundStyle" parent="android:Theme.Dialog">
        <item name="android:backgroundDimEnabled">false</item>
      </style>
    </resources>
    

    AndroidManifest.xml 这样做:

    <activity android:name=".SampleActivity" android:theme="@style/myBackgroundStyle">