我试图在没有操作栏(标题)和黑色状态栏的情况下设置我的应用主题,但我无法实现这一目标。我经历了关于这个的老话题,但没有找到任何解决方案。有什么帮助吗?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mrti.menu">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
答案 0 :(得分:1)
我建议您在自定义主题中设置颜色。从棒棒糖(和AppCompat)开始,值对应如下图所示:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">@color/primary_dark</item>
</style>
然后在您的清单中,将主题设置为AppTheme
。
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
如果您想以编程方式执行此操作,请尝试:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.BLACK);
}