我正在尝试制作一个Android启动器.我想实现一个完全透明的状态栏和导航栏,这里是我的主题xml文件.
<resources>
<style name="Theme" parent="android:Theme.Material.Wallpaper.NoTitleBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
最后两个项目不起作用,棒棒糖还有一个阴影.
这就是它的样子(注意状态栏和导航栏上实际上有一个阴影):

我想要达到的目标(新星发射器):

如何使状态栏和导航栏"透明"而不是"半透明"?
我知道在Android 4.4 KitKat(API 19)中,可以使状态栏透明.
但是,例如,Go Launcher Ex和其他人可以选择让它变得透明,而且它也适用于预装KitKat,对我来说(Android 4.3(Jelly Bean))以及我的Android 4.0(冰淇淋三明治)设备.
我不需要root或任何特殊权限来使用它.
下载Go Launcher Ex并亲自试用.对我来说,如果我需要root也可以.
但是他们是怎么做到的?如何在预KitKat设备上使Android的状态栏保持半透明状态?
---澄清事情---
看这些示例图片:
(注意,这是从我的股票银河笔记3中获取的Android 4.3和Go Launcher Ex.)
(同样适用于我的Galaxy S2和Android 4.0.)
没有透明的状态栏:

随着启用透明状态栏:(我想要实现这个预先4.4(API 19)设备)

我想创建一个真正的全屏活动,但屏幕顶部总是有一个黑色状态栏。安卓 9.0。
我已经尝试了几乎所有我能找到的谷歌和类似工作的现有应用程序。Manifest,code,style,AS 示例全屏活动,都试过了。
样式.xml:
<style name="AppThemeA" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
显现:
<activity android:name=".ScreenActivity" android:theme="@style/AppThemeA" />
Run Code Online (Sandbox Code Playgroud)
布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/rootLayout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
Kotlin(尝试过注释行并失败):
class ScreenActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
//setTheme(R.style.AppThemeDetector)
super.onCreate(savedInstanceState)
//window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
//window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
//window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_FULLSCREEN
/*
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_FULLSCREEN …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用此代码在我的应用程序中使状态栏透明:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(Color.TRANSPARENT);
Run Code Online (Sandbox Code Playgroud)
但它不起作用.状态栏只是更改颜色,变为灰色,不透明.我的错误在哪里?如何使状态栏透明?
我使用以下布局(main_activity.xml)
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:fitsSystemWindows="true"
android:text="@string/large_text" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
使用以下样式-v21
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
但我仍然无法存档透明状态栏
它看起来像这样
但是我想要这样的东西(新的Google报亭应用)
注意:我正在使用
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:support-v4:25.1.1'
compile 'com.android.support:design:25.1.1'
Run Code Online (Sandbox Code Playgroud) 我想隐藏默认操作栏,因此在清单文件中我有以下代码:
<style name="Theme.MyCompose" parent="Theme.Material.DayNight.NoActionBar">
</style>
<style name="Theme.Material.DayNight.NoActionBar" parent="@android:style/Theme.Material.Light.NoActionBar" />
Run Code Online (Sandbox Code Playgroud)
而效果是这样的:
我想要实现的目标是这样的:
摄影应覆盖白色区域。如何做到这一点?
更新1
在实施具有半透明状态栏和伴奏插图支持的解决方案后,我遇到了奇怪的行为。当窗口标志设置如下时:
window.setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
)
Run Code Online (Sandbox Code Playgroud)
当删除这些标志时,插图可以工作,但我有那个阴影:
android user-experience kotlin android-actionbar android-jetpack-compose
我希望在我的应用程序上有一个透明状态栏(所以背景会在它后面)但我希望底部的导航栏保持黑色.
我可以通过设置使两者都透明 getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
我可以通过设置使顶部半透明(部分透明) <item name="android:windowTranslucentStatus">true</item>
但是,如果不使底部透明,我也无法使顶部完全透明.使用<item name="android:statusBarColor">@android:color/transparent</item>或类似不起作用.
有谁知道如何在不影响导航栏的情况下制作完全透明的状态栏?
我想实现三件事情在同一时间:
解决方案
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)
只能达到1和3;
这里的解决方案只能达到1和2;
而且这里的解决方案只能达到2和3。
那么有没有办法实现1、2和3?
android statusbar android-view android-windowmanager android-window
是否可以隐藏导航栏而不隐藏状态栏?
我在我的样式的 xml 中试过这个
<item name="android:windowFullscreen">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
Run Code Online (Sandbox Code Playgroud)
我在活动中像这样隐藏了导航栏
val decorView = window.decorView
val uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
decorView.systemUiVisibility = uiOptions
Run Code Online (Sandbox Code Playgroud)
谢谢!!
编辑:
fun hideNavigationStatusBar(activity: Activity) {
activity.window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
val decorView = activity.window.decorView
val uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
decorView.systemUiVisibility = uiOptions
}
fun translucidNavigationBar(activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
val w = activity.window
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
}
}
Run Code Online (Sandbox Code Playgroud)
我可以使用第一种方法隐藏状态和导航栏,并使用第二种方法通过半透明导航保持状态,但我仍然无法保持状态并完全隐藏导航栏。
有谁知道用React Native透明化Android状态栏的方法吗?
不透明,透明。
我也在使用反应导航。
android ×10
statusbar ×6
android-view ×2
fullscreen ×1
java ×1
kotlin ×1
react-native ×1
styles ×1
transparency ×1
transparent ×1