我想隐藏我的安卓设备和平板电脑的顶部菜单栏。有人可以告诉我如何进行操作吗?谢谢任何帮助。
您可以通过在AndroidManifest.xml文件中的<application>
元素上设置android:theme属性为@android:style/Theme.NoTitleBar来实现此目的,如下所示:
<activity android:name=".Activity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android:theme="@style/Theme.AppCompat.NoActionBar"
对我有用。 - luckyging3rActionBar actionBar = getActionBar();
actionBar.hide();
getSupportActionBar().hide();
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
...
如果您导航到文件夹树 res/values/styles.xml,您可以将样式设置为继承自父样式。在我的情况下,这对于整个应用程序的解决方案非常有效。
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
onCreate()
方法中添加以下代码行。WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);
targetSdk
版本是11或以上(包括Honeycomb及其后续版本),那么你应该使用 Holo
风格。因此,在你的清单文件中,在 <application>
标签中使用以下属性:android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
application
标签中:android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
。这将使您的应用在全屏模式下运行。如果您想要有标题栏,只需创建一个自定义标题栏并将其放入所有其他活动都将继承的基本活动中即可。<item name="android:windowNoTitle">true</item>
它基本上做的与添加相同
android:theme="@android:style/Theme.NoTitleBar"
将该行添加到您的清单文件中,但您可以通过将该行添加到styles.xml中来保留自己的自定义样式
添加这个
ActionBar actionBar = getActionBar();
actionBar.hide();
不显示比显示后再隐藏更好。您可以通过在应用程序块的主AndroidManifest.xml文件中定义NoActionBar主题来禁用顶部标题ActionBar菜单的显示:
android:theme="@style/AppTheme.NoActionBar"
android:theme="@android:style/Theme.NoTitleBar"
。 - Paresh Mayani