Android Lollipop,以前称为“Android L”,最初在Google I / O 2014上展出。最终名称于10月15日确认。
Android Lollipop CardView 上的波纹效果
我试图通过在活动 XML 文件中设置 android:backgound 属性来让 CardView 在触摸时显示涟漪效果,如 Android 开发人员页面上所述,但它...
在 Android Lollipop 中使用意图搜索字符串打开设置页面
我正在尝试打开已输入搜索查询的“设置”页面 图片网址: https://i.sstatic.net/LE5sU.jpg 我知道我们可以通过意图打开“设置”页面。但是有可能...
我想知道是否有人知道如何制作带有透明操作栏的活动, 就像您进入应用程序页面时在新的 Google Play 商店中看到的那样。 我不在乎卷轴...
LRX210 更新后(Nexus 5)“执行 doInBackground() 时发生错误”
我只是想知道是否还有其他人遇到这个问题。 我有两台 Nexus 5,一台运行 5.0 LPX13D(开发预览版),另一台运行 5.0 LRX210(正式版本)。 在我的应用程序中,我调用
Android SecurityException:管理员不拥有该配置文件
我有一个设备管理器应用程序,我正在尝试使用自 API 21 起可用的 DevicePolicyManager 类的 setScreenCaptureDisabled(..) 函数。 DevicePolicyManager pManager = (android.app.ad...
将Androidcamera2 api YUV_420_888转换为RGB
我正在编写一个应用程序,它获取相机输入,将其转换为 RGB,以便进行一些处理。 它在使用 NV21 Yuv 格式的旧相机实现上运行良好。 我遇到的问题...
未找到 java.lang.String android.os.SystemProperties.native_get(java.lang.String) 的实现
每当我在设备上安装应用程序时都会出现错误。 03/24 18:56:08:启动应用程序 $ adb Push /home/itstym/AndroidStudioProjects/hlthee/app/build/outputs/apk/app-debug.apk /data/local/tmp/u...
使用 AppCompat ActionBarActivity 更改状态栏颜色
在我的一项活动中,我使用调色板更改了工具栏颜色。但在使用 ActionBarActivity 的 5.0 设备上,状态栏颜色是我的活动主题中 colorPrimaryDark 的颜色,所以我...
我想知道 Android 5 中是否可以在状态栏中包含滑块(应用程序)。调节亮度、音量等? 有些应用程序(例如 Play Music)也提供了 ui 中的
如何使用 adb shell 命令验证 Android 设备屏幕打开或关闭
尝试使用 mScreenOn=true 或 mPowerState=SCREEN_BRIGHT_BIT 检查设备屏幕打开或关闭。但以下命令在最新的 Android 版本中不起作用。它什么也没返回 正在关注
我正在尝试制作一个Android启动器。我想实现一个完全透明的状态栏和导航栏,这是我的主题xml文件。 <p>我正在尝试制作一个Android启动器。我想实现一个完全透明的状态栏和导航栏,这是我的主题xml文件。</p> <pre><code><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> </code></pre> <p>最后两项不起作用,棒棒糖上还有阴影。</p> <p>这就是它的样子(注意状态栏和导航栏上实际上有一个阴影): <img src="https://cdn.txt58.com/i/AWkuc3RhY2suaW1ndXIuY29tL2NFekQ2LmpwZw==" alt="enter image description here"/></p> <p>我想要实现的目标(nova 启动器):</p> <p><img src="https://cdn.txt58.com/i/AWkuc3RhY2suaW1ndXIuY29tL3AxRUVDLmpwZw==" alt="enter image description here"/></p> <p>如何让状态栏和导航栏“透明”而不是“半透明”?</p> </question> <answer tick="false" vote="160"> <h2>更新</h2> <p>您可以通过在 KitKat 上以编程方式实现相同的效果,然后通过在 <pre><code>FLAG_LAYOUT_NO_LIMITS</code></pre> 内设置 <pre><code>Window</code></pre> 标志。</p> <pre><code>if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = getWindow(); // in Activity's onCreate() for instance w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } </code></pre> <p>如果您为布局设置背景资源(<em>如颜色或图片</em>),您将在状态栏“下方”看到颜色或图片。</p> <pre><code><item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:statusBarColor">@color/primary_dark</item> </code></pre> <hr/> <h2>原答案</h2> <p>看起来 <pre><code>android:windowTranslucentStatus</code></pre> 和 <pre><code>android:windowTranslucentNavigation</code></pre> 应该是 <pre><code>true</code></pre> 而不是 <pre><code>false</code></pre></p> <pre><code><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">true</item> <item name="android:windowTranslucentNavigation">true</item> </style> </resources> </code></pre> <p>此外,您的透明活动/容器布局需要设置此属性:</p> <pre><code>android:fitsSystemWindows="true" </code></pre> <p>[来源][1] [1]:https://stackoverflow.com/a/29311321/1549700</p> </answer> <answer tick="false" vote="14"> <p>您可以使用此 kotlin 扩展函数,它将设置状态栏完全透明(在 <strong>API 23+</strong> 上,<pre><code>View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR</code></pre> 标志在 <strong>API 23+</strong> 上可用)和导航栏(在 <strong>API 27+</strong> 上,<pre><code>View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR</code></pre> 标志上)在 <strong>API 27+</strong> 上可用),否则它将使用 <pre>API 21+</pre><strong> 上的 </strong><code>systemUiScrim</code></p> 颜色 <pre><code>fun Activity.transparentStatusAndNavigation( systemUiScrim: Int = Color.parseColor("#40000000") // 25% black ) { var systemUiVisibility = 0 // Use a dark scrim by default since light status is API 23+ var statusBarColor = systemUiScrim // Use a dark scrim by default since light nav bar is API 27+ var navigationBarColor = systemUiScrim val winParams = window.attributes if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { systemUiVisibility = systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR statusBarColor = Color.TRANSPARENT } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { systemUiVisibility = systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR navigationBarColor = Color.TRANSPARENT } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { systemUiVisibility = systemUiVisibility or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION window.decorView.systemUiVisibility = systemUiVisibility } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { winParams.flags = winParams.flags or WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { winParams.flags = winParams.flags and (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION).inv() window.statusBarColor = statusBarColor window.navigationBarColor = navigationBarColor } window.attributes = winParams } </code></pre> <p><strong>API 21+</strong> <a href="https://i.stack.imgur.com/Iagma.png" target="_blank"><img src="https://cdn.txt58.com/i/AWkuc3RhY2suaW1ndXIuY29tL0lhZ21hLnBuZw==" alt=""/></a> <strong>API 27+</strong> <a href="https://i.stack.imgur.com/4k97R.png" target="_blank"><img src="https://cdn.txt58.com/i/AWkuc3RhY2suaW1ndXIuY29tLzRrOTdSLnBuZw==" alt=""/></a></p> </answer> <answer tick="false" vote="14"> <p>适用于 API 29 及以上使用</p> <pre><code><style name="Your.Theme"> <item name="android:navigationBarColor">@android:color/transparent</item> <item name="android:enforceNavigationBarContrast">false</item> </style> </code></pre> </answer> <answer tick="false" vote="9"> <p>我使用它是因为它保持状态栏和导航栏的高度</p> <pre><code><!-- Base application theme. --> <style name="theme" parent="android:Theme.Material.Wallpaper.NoTitleBar"> <item name="android:navigationBarColor">#00000000</item> <item name="android:statusBarColor">#00000000</item> </style> </code></pre> <p>这确实需要 API 21+ 但是</p> </answer> <answer tick="false" vote="4"> <p>以下代码是我在项目中使用的示例:</p> <p>样式.xml</p> <p></p> <pre><code><style name="FadingActionBarTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar"> <item name="android:actionBarStyle">@style/FadingActionBarWidget</item> </style> <style name="FadingActionBarWidget.Transparent"> <item name="android:background">@android:color/transparent</item> </style> <style name="FadingActionBarTheme.TranslucentActionBar"> <item name="android:icon">@drawable/ic_ab_icon</item> <item name="android:actionBarStyle">@style/FadingActionBarWidget.Transparent</item> <item name="android:windowActionBarOverlay">true</item> <item name="android:windowContentOverlay">@null</item> </style> </code></pre> <p>AndroidManifest.xml</p> <pre><code><activity android:name=".MyActivity" android:label="@string/app_name" android:theme="@style/FadingActionBarTheme.TranslucentActionBar"> </activity> </code></pre> </answer> <answer tick="false" vote="4"> <p>您需要向主题添加 <pre><code>android:windowDrawsSystemBarBackgrounds</code></pre> 标志</p> <pre><code><item name="android:windowDrawsSystemBarBackgrounds">true</item> </code></pre> <p>或者在onCreate()中调用这个</p> <pre><code>getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); </code></pre> </answer> <answer tick="false" vote="4"> <h2><strong>100% 工作代码</strong></h2> <h2>完全透明的状态栏和导航栏</h2> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initStatusNavBar(); transparentStatusAndNavigation(); showSystemUI(); // hideSystemUI(); } public static void transparentStatusAndNavigation(Activity activity) { Window window = activity.getWindow(); // make full transparent statusBar if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) { setWindowFlag(window, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, true); } if (Build.VERSION.SDK_INT >= 19) { int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; visibility = visibility | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; window.getDecorView().setSystemUiVisibility(visibility); } if (Build.VERSION.SDK_INT >= 21) { int windowManager = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; windowManager = windowManager | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; setWindowFlag(window, windowManager, false); window.setStatusBarColor(Color.TRANSPARENT); window.setNavigationBarColor(Color.TRANSPARENT); } } private static void setWindowFlag(final int bits, boolean on) { Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); } </code></pre> <h2>设置状态栏和导航栏高度和颜色:</h2> <p><strong>在activity_main.xml中:</strong></p> <pre><code><?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/mainLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:orientation="vertical"> <View android:id="@+id/status_bg" android:layout_width="match_parent" android:layout_height="0dp" android:background="@color/primaryColorLightThemeDarkTrans" tools:layout_height="24dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <!--Write Code Here--> </LinearLayout> <View android:id="@+id/nav_bg" android:layout_width="match_parent" android:layout_height="0dp" android:background="@color/navColorLightThemeTrans" tools:layout_height="?actionBarSize" /> </LinearLayout> </code></pre> <p><strong>在java代码中:</strong></p> <pre><code>private void initStatusNavBar() { int statusBarHeight = getStatusBarHeight(activity); int navBarHeight = getNavigationBarHeight(activity, statusBarHeight); View statusBarBackground = findViewById(R.id.status_bg); statusBarBackground.getLayoutParams().height = statusBarHeight; View navBarBackground = findViewById(R.id.nav_bg); if (Build.VERSION.SDK_INT >= 21) { setNavigationBarHeight(activity, navBarBackground); } else { navBarBackground.getLayoutParams().height = navBarHeight; } } public static int getStatusBarHeight(Activity activity) { final Resources resources = activity.getResources(); final int resId = resources.getIdentifier("status_bar_height", "dimen", "android"); if (resId > 0) { return resources.getDimensionPixelSize(resId); } return 0; } public static int getNavigationBarHeight(Activity activity, int statusBarHeight) { Point point = getNavigationBarSize(activity); int height = point.y; if (isNotchDisplay(statusBarHeight)) { height = height - statusBarHeight; } return height; } private static Point getNavigationBarSize(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Point appUsableSize = getAppUsableScreenSize(context); Point realScreenSize = getRealScreenSize(context); // navigation bar on the right if (appUsableSize.x < realScreenSize.x) { return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y); } // navigation bar at the bottom if (appUsableSize.y < realScreenSize.y) { return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y); } // navigation bar is not present return new Point(); } return new Point(); } private static Point getAppUsableScreenSize(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Point size = new Point(); if (null != windowManager) { Display display = windowManager.getDefaultDisplay(); display.getSize(size); } return size; } private static Point getRealScreenSize(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Point size = new Point(); if (null != windowManager) { Display display = windowManager.getDefaultDisplay(); if (Build.VERSION.SDK_INT >= 17) { display.getRealSize(size); } else { try { size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display); size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } } return size; } private static boolean isNotchDisplay(int statusBarHeight) { int normalStatusBarHeight = dpToPxForNav(25); return statusBarHeight > normalStatusBarHeight; } private static int dpToPxForNav(float dp) { DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); float px = dp * (metrics.densityDpi / 160f); return Math.round(px); } public static void setNavigationBarHeight(Activity activity, View navBarBackground) { ViewCompat.setOnApplyWindowInsetsListener(navBarBackground, (v, insets) -> { int navBarHeight = insets.getSystemWindowInsetBottom(); navBarBackground.getLayoutParams().height = navBarHeight; return insets.consumeSystemWindowInsets(); }); } @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) public void showSystemUI() { statusBarBackground.setVisibility(View.VISIBLE); navBarBackground.setVisibility(View.VISIBLE); mDecorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) public void hideSystemUI() { statusBarBackground.setVisibility(View.GONE); navBarBackground.setVisibility(View.GONE); mDecorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } </code></pre> <h2>styles.xml 中的主题:</h2> <pre><code><style name="MyAppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar"> <!--For Notch Issues--> <item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="o_mr1">shortEdges</item> <item name="windowActionBarOverlay">true</item> <item name="colorPrimary">@color/primaryColor</item> <item name="colorPrimaryDark">@color/primaryColorDark</item> <item name="colorAccent">@color/accentColor</item> <item name="colorControlHighlight">@color/colorHighlight</item> <item name="android:windowBackground">@android:color/white</item> <item name="android:textColorPrimary">#fff6d7</item> <item name="android:colorPrimary" tools:targetApi="lollipop">@color/primaryColor</item> <item name="android:colorPrimaryDark" tools:targetApi="lollipop">@color/primaryColorDark</item> <item name="android:statusBarColor" tools:targetApi="lollipop">@color/primaryColorDark</item> <item name="android:colorAccent" tools:targetApi="lollipop">@color/accentColorLight</item> <item name="android:colorControlHighlight" tools:targetApi="lollipop">@color/colorHighlight</item> <item name="android:navigationBarColor" tools:targetApi="lollipop">@color/navColor</item> <item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item> <item name="android:windowActionBarOverlay">true</item> <item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item> </style> </code></pre> <h2>在 AndroidManifest.xml 中:</h2> <pre><code> <activity android:name="com.MyActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:screenOrientation="fullSensor" android:theme="@style/MyAppTheme" /> </code></pre> </answer> <answer tick="false" vote="1"> <p>在状态栏下绘制布局:</p> <p>值/styles.xml</p> <pre><code><item name="android:windowTranslucentStatus">true</item> </code></pre> <p>值-v21/styles.xml</p> <pre><code><item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:statusBarColor">@color/colorPrimaryDark</item> </code></pre> <p>使用 CoordinatorLayout/DrawerLayout ,它已经处理了 FitsSystemWindows 参数或创建您自己的布局,如下所示:</p> <pre><code>public class FitsSystemWindowConstraintLayout extends ConstraintLayout { private Drawable mStatusBarBackground; private boolean mDrawStatusBarBackground; private WindowInsetsCompat mLastInsets; private Map<View, int[]> childsMargins = new HashMap<>(); public FitsSystemWindowConstraintLayout(Context context) { this(context, null); } public FitsSystemWindowConstraintLayout(Context context, AttributeSet attrs) { this(context, attrs, 0); } public FitsSystemWindowConstraintLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); if (ViewCompat.getFitsSystemWindows(this)) { ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat insets) { FitsSystemWindowConstraintLayout layout = (FitsSystemWindowConstraintLayout) view; layout.setChildInsets(insets, insets.getSystemWindowInsetTop() > 0); return insets.consumeSystemWindowInsets(); } }); setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); TypedArray typedArray = context.obtainStyledAttributes(new int[]{android.R.attr.colorPrimaryDark}); try { mStatusBarBackground = typedArray.getDrawable(0); } finally { typedArray.recycle(); } } else { mStatusBarBackground = null; } } public void setChildInsets(WindowInsetsCompat insets, boolean draw) { mLastInsets = insets; mDrawStatusBarBackground = draw; setWillNotDraw(!draw && getBackground() == null); for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); if (child.getVisibility() != GONE) { if (ViewCompat.getFitsSystemWindows(this)) { ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) child.getLayoutParams(); if (ViewCompat.getFitsSystemWindows(child)) { ViewCompat.dispatchApplyWindowInsets(child, insets); } else { int[] childMargins = childsMargins.get(child); if (childMargins == null) { childMargins = new int[]{layoutParams.leftMargin, layoutParams.topMargin, layoutParams.rightMargin, layoutParams.bottomMargin}; childsMargins.put(child, childMargins); } if (layoutParams.leftToLeft == LayoutParams.PARENT_ID) { layoutParams.leftMargin = childMargins[0] + insets.getSystemWindowInsetLeft(); } if (layoutParams.topToTop == LayoutParams.PARENT_ID) { layoutParams.topMargin = childMargins[1] + insets.getSystemWindowInsetTop(); } if (layoutParams.rightToRight == LayoutParams.PARENT_ID) { layoutParams.rightMargin = childMargins[2] + insets.getSystemWindowInsetRight(); } if (layoutParams.bottomToBottom == LayoutParams.PARENT_ID) { layoutParams.bottomMargin = childMargins[3] + insets.getSystemWindowInsetBottom(); } } } } } requestLayout(); } public void setStatusBarBackground(Drawable bg) { mStatusBarBackground = bg; invalidate(); } public Drawable getStatusBarBackgroundDrawable() { return mStatusBarBackground; } public void setStatusBarBackground(int resId) { mStatusBarBackground = resId != 0 ? ContextCompat.getDrawable(getContext(), resId) : null; invalidate(); } public void setStatusBarBackgroundColor(@ColorInt int color) { mStatusBarBackground = new ColorDrawable(color); invalidate(); } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (mDrawStatusBarBackground && mStatusBarBackground != null) { int inset = mLastInsets != null ? mLastInsets.getSystemWindowInsetTop() : 0; if (inset > 0) { mStatusBarBackground.setBounds(0, 0, getWidth(), inset); mStatusBarBackground.draw(canvas); } } } } </code></pre> <p>main_activity.xml</p> <pre><code><FitsSystemWindowConstraintLayout 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"> <ImageView android:layout_width="0dp" android:layout_height="0dp" android:fitsSystemWindows="true" android:scaleType="centerCrop" android:src="@drawable/toolbar_background" app:layout_constraintBottom_toBottomOf="@id/toolbar" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="0dp" android:layout_height="?attr/actionBarSize" android:background="@android:color/transparent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <LinearLayout android:layout_width="0dp" android:layout_height="0dp" android:gravity="center" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@id/toolbar"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="Content" android:textSize="48sp" /> </LinearLayout> </FitsSystemWindowConstraintLayout> </code></pre> <p>结果:</p> <p><a href="https://i.stack.imgur.com/DlHNA.png" target="_blank"><img src="https://cdn.txt58.com/i/AWkuc3RhY2suaW1ndXIuY29tL0RsSE5BLnBuZw==" alt=""/></a></p> </answer> <answer tick="false" vote="0"> <p>对于那些想要在 KitKat 及以上版本上完全透明的状态栏和导航栏的人来说,使用 <pre><code>windowTranslucentNavigation</code></pre> 与 @Machado 的 Lollipop 答案有一个小冲突,为了防止这种冲突,将样式分开</p> <p>样式.xml</p> <pre><code><style name="LockScreenStyle" parent="@android:style/Theme.Wallpaper.NoTitleBar"> <item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item> <item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item> </style> </code></pre> <p>styles.xml <strong>(v21)</strong></p> <pre><code><style name="LockScreenStyle" parent="@android:style/Theme.Wallpaper.NoTitleBar"> <item name="android:windowDrawsSystemBarBackgrounds">true</item> </style> </code></pre> <p>MyClass.java</p> <pre><code>if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = getWindow(); // in Activity's onCreate() for instance w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); } } </code></pre> </answer> <answer tick="false" vote="0"> <p>您还可以将 colorPrimary 和 colorPrimaryDark 的 alpha 更改为 00,然后将其添加到您的 onCreateMethod 中:</p> <pre><code> window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN </code></pre> <p>并将其添加到您的活动中:</p> <pre><code>android:fitsSystemWindows="true" </code></pre> </answer> <answer tick="false" vote="0"> <p>这是为像我这样使用 Nativescript + Angular 的新人准备的。我从<a href="https://nativescript.org/blog/open-source-code-samples-in-the-nativescript-marketplace/" rel="nofollow noreferrer">NTS 市场</a> 上的一个空白模板开始。然后,对于我的特定用途,我需要顶部的状态栏始终透明(类似于 iOS 风格),导航栏(底部)在某些组件/模块上完全透明(不是半透明!),而在其他组件/模块上则不透明。如果一切都是根据 NTS 设置的协议完成的,那么您应该有一个与此类似的 main.ts (我的解决方案的先决条件) <a href="https://i.stack.imgur.com/J0G2T.png" target="_blank"><img src="https://cdn.txt58.com/i/AWkuc3RhY2suaW1ndXIuY29tL0owRzJULnBuZw==" alt=""/></a></p> <p>我将我的作品分成两部分,首先是顶部,然后是底部。对于顶部,我发现<a href="https://stackoverflow.com/questions/58938185/how-can-i-change-the-statusbar-color-or-set-it-to-transparent-on-android-using">这个答案</a>有效。所以你应该有一个如下所示的 main.ts 文件。</p> <pre><code>import { platformNativeScriptDynamic } from "@nativescript/angular"; import { AppModule } from "./app/app.module"; import * as application from "tns-core-modules/application"; import { Color } from "@nativescript/core"; platformNativeScriptDynamic().bootstrapModule(AppModule); declare var android; application.android.on(application.AndroidApplication.activityCreatedEvent, (event) => { const activity = event.activity; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { activity.getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); activity.getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); activity.getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); activity.getWindow().setStatusBarColor(android.graphics.Color.TRANSPARENT); activity.getWindow().setNavigationBarColor(android.graphics.Color.TRANSPARENT); } else { activity.getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); activity.getWindow().setNavigationBarColor(android.graphics.Color.TRANSPARENT); } const parent = activity.findViewById(android.R.id.content); for (let i = 0; i < parent.getChildCount(); i++) { const childView = parent.getChildAt(i); if (childView instanceof android.view.ViewGroup) { childView.setFitsSystemWindows(true); childView.setClipToPadding(true); } } }); </code></pre> <p>然后为了向导航栏添加透明度,我按照 <a href="https://stackoverflow.com/questions/58938185/how-can-i-change-the-statusbar-color-or-set-it-to-transparent-on-android-using">this</a> 并将其添加到上面 main.ts 文件的第 24 行。 <pre><code>activity.getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);</code></pre></p> <p>现在请注意,我们还必须尊重 styles.xml 文件,因此我的 styles.xml 文件(App_Resources\Android\src\main es alues\styles.xml) 看起来像这样:</p> <pre><code> <?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <!-- theme to use FOR launch screen--> <style name="LaunchScreenThemeBase" parent="Theme.AppCompat.Light.NoActionBar"> <item name="toolbarStyle">@style/NativeScriptToolbarStyle</item> <item name="colorPrimary">@color/ns_primary</item> <item name="colorPrimaryDark">@color/ns_primaryDark</item> <item name="colorAccent">@color/ns_accent</item> <item name="android:windowBackground">@drawable/splash_screen</item> <item name="android:statusBarColor">@color/transparent</item> </style> <style name="LaunchScreenTheme" parent="LaunchScreenThemeBase"></style> <!-- theme to use AFTER launch screen is loaded--> <style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar"> <item name="toolbarStyle">@style/NativeScriptToolbarStyle</item> <item name="colorPrimary">@color/ns_primary</item> <item name="colorPrimaryDark">@color/ns_primaryDark</item> <item name="colorAccent">@color/ns_accent</item> <item name="android:statusBarColor">@color/transparent</item> <item name="android:navigationBarColor">@color/transparent</item> <item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:windowTranslucentNavigation">false</item> </style> <style name="AppTheme" parent="AppThemeBase"></style> <!-- theme for action-bar --> <style name="NativeScriptToolbarStyleBase" parent="Widget.AppCompat.Toolbar"> <item name="android:background">@color/transparent</item> <item name="theme">@color/transparent</item> <item name="popupTheme">@color/transparent</item> </style> <style name="NativeScriptToolbarStyle" parent="NativeScriptToolbarStyleBase"></style> </code></pre> <p>我花了大约2-3天的时间才弄清楚,希望这会有所帮助</p> </answer> <answer tick="false" vote="0"> <h1>来自 Android R</h1> <pre><code>fun Activity.setTransparentStatusBar() { WindowCompat.setDecorFitsSystemWindows(window, false) window.statusBarColor = Color.TRANSPARENT window.navigationBarColor = Color.TRANSPARENT } </code></pre> <p>就是这样</p> </answer> <answer tick="false" vote="0"> <p>更新:只需使用 <pre><code>androidx.activity.enableEdgeToEdge()</code></pre> 代替</p> <p>已过时:</p> <p>基于 <a href="https://stackoverflow.com/a/62483455">Arpan Sarkar</a> 答案只是使用 WindowCompat 来减少代码量并避免使用已弃用的定义,</p> <pre><code>fun Activity.transparentSystemBars( behindStatusBarIsLight: Boolean, behindNavigationBarIsLight: Boolean, ) { // Android 4 is hard to debug and apparently ViewCompat.setOnApplyWindowInsetsListener isn't // reporting any value there so let's skip and simplify if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return WindowCompat.setDecorFitsSystemWindows(window, false) if (behindStatusBarIsLight || behindNavigationBarIsLight) { val insetsController: WindowInsetsControllerCompat = WindowCompat.getInsetsController(window, window.decorView) if (behindStatusBarIsLight) insetsController.isAppearanceLightStatusBars = true if (behindNavigationBarIsLight) insetsController.isAppearanceLightNavigationBars = true } val isLightStatusBarAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M val isLightNavigationBarAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O val shouldStatusBarBeTransparent = !behindStatusBarIsLight || isLightStatusBarAvailable val shouldNavigationBarBeTransparent = !behindNavigationBarIsLight || isLightNavigationBarAvailable val systemUiScrim = ColorUtils.setAlphaComponent(Color.BLACK, 0x40) // 25% black window.statusBarColor = if (shouldStatusBarBeTransparent) Color.TRANSPARENT else systemUiScrim window.navigationBarColor = if (shouldNavigationBarBeTransparent) Color.TRANSPARENT else systemUiScrim // You may set android:enforceNavigationBarContrast to false in style.xml as doing it in code isn't as effective apparently. } </code></pre> <p>Material 库中还有 <a href="https://github.com/material-components/material-components-android/blob/1a91e68/lib/java/com/google/android/material/internal/EdgeToEdgeUtils.java" rel="nofollow noreferrer">EdgeToEdgeUtils.applyEdgeToEdge</a>,它可以工作,但不应该被普通开发人员使用,猜测有一天它会提供给公众。</p> </answer> </body></html>
我使用的是运行Android 5.0的设备,minSdk是21,targetSdk是22。 应用描述 我正在使用一个有 2 个活动的应用程序,活动 A 包含一个带有图片和文本的 GridView 以及…
如何在android Lollipop中在xml中添加RecyclerView
我已将我的 Android SDK 更新为 Android 5.0 (API 21);我还更新了平台工具和构建工具。 我收到无法找到以下课程: - android.support.v7.widget.
我正在为 Android 5.0 重新编译一些可执行文件,因为它要求可执行文件是 PIE。我能够为 ARM 重新编译它,只需在配置时添加一些参数(使用独立工具链......
Android SeekBar的progressBackgroundTint在API v21中没有效果。
我注意到,当改变我的SeekBar的progressBackgroundTint属性时,它被完全忽略了,没有任何效果。不管我把它设置成什么颜色,它总是显示为灰色,在我的 ...
在5版中使用getBackground().setAlpha的按钮--棒棒糖无法正常工作。
我有这段代码,从API 14开始,每个版本都能用,但在Android 5.0(棒棒糖)上不能正常工作。下面是我想让按钮出现的方式。点击button1 buttonArrivals......
我正在开发具有设备所有者特权的应用程序,我必须实现Android Lollipop中引入的“屏幕固定”功能。根据开发人员博客,我们可以固定任何应用程序...
如何信任具有交叉签名根的SSL证书在android <= 5上已过期
我为使用Comodo / Sectigo SSL证书的公司工作。但是突然之间,我们的应用在使用ok 4客户端的android 4和5版本中将POST发送到服务器时开始引发此错误。 ...
Html.toHtml()未解析BackgroundColorSpan(Android Lollipop)
我正在为我的应用编写api 21支持,问题是BackgroundColorSpan无法通过此api的Html.toHtml()进行解析。有办法解决吗?可扩展的屏幕快照Api 21-Html.toHtml(...