调用android对话框而不褪色背景

时间:2023-03-21
本文介绍了调用android对话框而不褪色背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有这个漂亮的对话框视图,我将 UserInputDialog 类设置为:

I have this nice dialog view I set my UserInputDialog class to:

    <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>

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

I want my dialog to show up but for the background to not fade out. Is this possible? Cause the view that calls this dialog has a neato background I would like to be shown as a backdrop to the dialog.

我在网上找到了这个:

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

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

but not sure how to apply that to my dialog? I have a class called public class UserInputDialog extends Dialog implements OnClickListener. It sets its content view to the layout described above.

我想我做得很好,只是不知道如何添加那种风格,所以我不能淡化背景.

I think I am doing this all right, just not sure how to add that style so I can NOT fade the background.

第二个问题:您能否通过使用主题在您的对话框上获得新外观(比如在其中显示带有文本的图像或图标)?

Secondary question: Can you get new looks on your dialog (by say having an image or icon display with your text there) by using Themes?

推荐答案

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

Create a res/values/styles.xml file and add this to it.

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

并将主题应用到您的活动中.

And apply the theme to your activity.

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

这篇关于调用android对话框而不褪色背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:如何在对话框中处理后退按钮? 下一篇:在显示对话框时,我得到“在 onSaveInstanceState 之后无法执行此操作";

相关文章