调用android对话框而不会使背景褪色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3113812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Calling android dialog without it fading the background
提问by Codejoy
I have this nice dialog view I set my UserInputDialog class to:
我有一个很好的对话框视图,我将 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>
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.
我希望我的对话框显示出来,但背景不会淡出。这可能吗?因为调用这个对话框的视图有一个neato 背景,我想作为对话框的背景显示。
I found this online:
我在网上找到了这个:
<style name="doNotDim" parent="@android:style/Theme.Dialog">
<item name="android:backgroundDimAmount">0</item>
</style >
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.
但不确定如何将其应用于我的对话框?我有一个名为public class UserInputDialog extends Dialog implements OnClickListener
. 它将其内容视图设置为上述布局。
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?
次要问题:您能否通过使用主题在对话框中获得新外观(比如在那里显示带有文本的图像或图标)?
采纳答案by Robby Pond
Create a res/values/styles.xml file and add this to it.
创建 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>
And apply the theme to your activity.
并将主题应用于您的活动。
<activity android:name=".SampleActivity" android:theme="@style/Theme.DoNotDim">
回答by Andrewx2
You can also remove the dim effect by code with the following:
您还可以使用以下代码删除暗淡效果:
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
回答by John P.
Create a custom style and place it in your values folder
创建自定义样式并将其放置在您的值文件夹中
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YourCustomStyle" parent="android:Theme">
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
To set a style to an individual dialog you can use
要将样式设置为单个对话框,您可以使用
Dialog dialog = new Dialog(context, R.style.YourCustomStyle);
回答by activesince93
For displaying dialog like TrueCallerdo this:
要显示像TrueCaller这样的对话框,请执行以下操作:
In styles.xml
file.
在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>
In AndroidManifest.xml
do this:
在AndroidManifest.xml
做到这一点:
<activity android:name=".SampleActivity" android:theme="@style/myBackgroundStyle">