我想隐藏actionBar,但是它有点褪色了:
样式:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/background</item>
<item name="colorPrimaryDark">@color/background</item>
<item name="android:windowBackground">@color/background</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
</style>
清单:
<application
android:configChanges="orientation|screenSize|layoutDirection"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
结果:
稍微褪色,我只是遇到了棉花糖设备(6.0.1)的问题
答案 0 :(得分:0)
您仍在使用具有操作栏的AppTheme
将此样式添加到样式文件中
<style name = "NoActionBar" parent = "@android:style/Theme.Holo.Light">
<item name = "android:windowActionBar">false</item>
<item name = "android:windowNoTitle">true</item>
</style>
,您需要更改
android:theme="@style/AppTheme"
清单中的
android:theme = "@style/NoActionBar"
<application
android:configChanges="orientation|screenSize|layoutDirection"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/NoActionBar">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
还有另一种隐藏操作栏的方法,例如:
1。
<activity android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
2。使用隐藏方法
// Hide ActionBar
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
3。或使用 requestWindowFeature(Window.FEATURE_NO_TITLE);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hide ActionBar
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}
答案 1 :(得分:0)
创建一个新样式的xml并将其更改为以下内容
Theme.AppCompat.Light.NoActionBar
可能有效...