Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何获得半透明的状态栏?_Android - Fatal编程技术网

Android 如何获得半透明的状态栏?

Android 如何获得半透明的状态栏?,android,Android,我已经设法得到一个完全透明的状态栏,但我想要一个半透明的。下面是我为实现完全透明的状态栏而添加的代码 在my styles.xml中,我添加了以下内容: <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item> 在my activity.j

我已经设法得到一个完全透明的状态栏,但我想要一个半透明的。下面是我为实现完全透明的状态栏而添加的代码

在my styles.xml中,我添加了以下内容:

        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
在my activity.java的onCreate中:

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
这就是我想要实现的目标:
在colors.xml中创建新颜色

88000000

然后在style.xml中更改主暗颜色


@color/blackT

下面是一些可以在代码中实现的选项

备选案文1: 在xml文件上

 android:background ="#88676767" or "#88000000"
备选案文2。 在图像视图或任何其他视图上

view.setColorFilter(Color.argb(150, 155, 155, 155),   Mode.SRC_ATOP);
备选案文3: 在你的布局上

LinearLayout ll = (LinearLayout) findViewById(R.id.test_layout);
Drawable dd = getResources().getDrawable(R.drawable.test);
dd.setAlpha(50);
ll.setBackgroundDrawable(dd);

这可能会对您有所帮助。

您的问题有多种可能的解决方案:

一,。切换到全屏窗口

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
二,。XML方式

<style name="AppTheme.MainActivity" parent="AppTheme">
    <item name="colorPrimary">#ffffff</item>
    <item name="colorPrimaryDark">#ebebeb</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="windowNoTitle">true</item>
</style>

尝试全屏getWindow.setFlagsWindowManager.LayoutParams.FLAG_全屏,WindowManager.LayoutParams.FLAG_全屏;这是可行的,但是状态栏一开始是不可见的,我必须把它拉下来。我能让它永久停留在那里吗?我想这是安卓的不变行为。当你要求全屏显示时,出于正常原因,他们会隐藏状态栏。我发现了一个反射黑客:。但是,这可能不是你的情况-请继续尝试。我也无法让它工作。我会坚持你的第一个建议。这可不行。结果仍然一样。你可以查看这篇文章。
<style name="AppTheme.MainActivity" parent="AppTheme">
    <item name="colorPrimary">#ffffff</item>
    <item name="colorPrimaryDark">#ebebeb</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="windowNoTitle">true</item>
</style>