如何调暗屏幕上在Android中点击一个按钮? [英] How to dim a screen on click of a button in android?

查看:174
本文介绍了如何调暗屏幕上在Android中点击一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何变暗/调暗当前屏幕上点击一个按钮。请帮帮我。

How do i darken/dim the current screen on click of a button. PLease help me.

推荐答案

下面是一个解决方案,虽然它可能不是最好的:

Here's one solution, though it may not be the best:

下创建RES /值styles.xml。添加以下code:

create styles.xml under res/values. Add the following code:

<style name="Theme.Translucent" parent="android:Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@color/cache_color</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">true</item>
 </style>

注意 @色/ cache_color &LT;颜色名称=cache_color&GT;#00000000 LT; /彩色&GT; 。现在点击您的自定义按钮应发送意图的活动(例如,FooActivity)。因此,在你的清单中声明如下:

Note that @color/cache_color is <color name="cache_color">#00000000</color>. Now clicking your custom button should send an intent to an activity (e.g., FooActivity). So declare this in your manifest:

<activity android:name="com.FooActivity" android:theme="@style/Theme.Translucent"></activity>

和瞧,当你的按钮的监听器被调用的屏幕变暗!

and voila, the screen is dimmed when your button's listener is called!

这篇关于如何调暗屏幕上在Android中点击一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆