如何永久禁用操作栏

发布于 2024-12-20 22:06:45 字数 126 浏览 0 评论 0原文

我可以使用以下代码将操作栏隐藏在蜂窝中:

getActionBar().hide();

但是当键盘打开并且用户复制粘贴任何内容时,操作栏会再次显示。 如何永久禁用操作栏?

I can hide the action bar in honeycomb using this code:

getActionBar().hide();

But when the keyboard opens, and user copy-pastes anything, the action bar shows again.
How can I disable the action bar permanently?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(29

热鲨 2024-12-27 22:06:45

如果您正在使用 Theme.Holo.Light 并希望在 3.2 之前的设备上使用 Theme.Holo.Light.NoActionBar 变体,您可以将其添加到您的 样式中.xml

<style name="NoActionBar" parent="@android:style/Theme.Holo.Light">
    <item name="android:windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
</style> 

然后将其设置为您的活动的主题:

<activity android:theme="@style/NoActionBar" ... />

If you are using Theme.Holo.Light and want to use the Theme.Holo.Light.NoActionBar variant on pre 3.2 devices you can add this to your styles.xml:

<style name="NoActionBar" parent="@android:style/Theme.Holo.Light">
    <item name="android:windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
</style> 

and then set it as your activity's theme:

<activity android:theme="@style/NoActionBar" ... />
早乙女 2024-12-27 22:06:45

通过在Manifest中设置活动主题,

<activity
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
....
>

By setting activity theme in Manifest,

<activity
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
....
>
涫野音 2024-12-27 22:06:45

我在 onCreate 函数中使用以下代码:

ActionBar actionBar = getSupportActionBar();
actionBar.hide();

来源:
https://developer.android.com/guide/topics/ui/actionbar.html

I use the following code inside my onCreate function:

ActionBar actionBar = getSupportActionBar();
actionBar.hide();

Source:
https://developer.android.com/guide/topics/ui/actionbar.html

温折酒 2024-12-27 22:06:45
<application
    .
    .
    android:theme="@android:style/Theme.Holo.Light.NoActionBar"
    . >

也许这对你有帮助

<application
    .
    .
    android:theme="@android:style/Theme.Holo.Light.NoActionBar"
    . >

maybe this help you

你的他你的她 2024-12-27 22:06:45

Android Studio 默认生成的 Activity 超类是 ActionBarActivity,然后其他响应中的解决方案都不起作用。要解决这个问题,只需将 superclass: 更改

public class xxxActivity extends ActionBarActivity{

为:

public class xxxActivity extends Activity {

With the Android Studio default generated Activity superclass is ActionBarActivity and then, none of solution in other responses works. To solve just change superclass:

public class xxxActivity extends ActionBarActivity{

to:

public class xxxActivity extends Activity {
懷念過去 2024-12-27 22:06:45

如果你想全屏,没有actionBar和Title。

将其添加到 style.xml 中

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
      <item name="windowActionBar">false</item>
      <item name="windowNoTitle">true</item>
      <item name="android:windowFullscreen">true</item>
</style>

并使用 manifest.xml 中的样式。

android:theme="@style/AppTheme.NoActionBar" 

If you want to get full screen without actionBar and Title.

Add it in style.xml

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
      <item name="windowActionBar">false</item>
      <item name="windowNoTitle">true</item>
      <item name="android:windowFullscreen">true</item>
</style>

and use the style at manifest.xml.

android:theme="@style/AppTheme.NoActionBar" 
如日中天 2024-12-27 22:06:45

转到 styles.xml
将此 DarkActionBar 更改为 NoActionBar

style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

Go to styles.xml
Change this DarkActionBar to NoActionBar

style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
我要还你自由 2024-12-27 22:06:45
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    getSupportActionBar().hide();
}
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    getSupportActionBar().hide();
}
玩心态 2024-12-27 22:06:45

我发现提供自定义主题且没有操作栏的最佳方法是为我的项目中的所有活动创建一个超类,并在它的 onCreate() 中调用以下代码行 -

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

它总是对我有用。这种方法的唯一问题是,启动应用程序时您将在几分之一秒内看到操作栏(不是活动,而是完整的应用程序)。

The best way I found which gives custom themes and no action bar, is to create a SuperClass for all activities in my project and in it's onCreate() call the following line of code -

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

It always work for me. The only issue in this approach is, you'll see action bar for a fraction of second when starting the app (Not the activity, the complete app).

白鸥掠海 2024-12-27 22:06:45

您可以简单地强制隐藏操作栏:

ActionBar  actionbar = getSupportActionBar();
actionbar.hide();

只需使用默认主题,如果设置为全屏,效果会很好

You can force hide the action bar simply:

ActionBar  actionbar = getSupportActionBar();
actionbar.hide();

Just use your default theme, it will work good if fullscreen is set

幸福还没到 2024-12-27 22:06:45

不要使用 Holo 主题,操作栏将会消失。
这段代码适用于 API 8+,支持 lib v7:

<style name="NoActionBar" parent="@style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>

为您的活动设置主题:

<activity android:theme="@style/NoActionBar" ... />

并在您的活动类中。

即使它扩展了 ActionBarActivity,它也能工作。

Don't use Holo theme and the Actionbar will disappear.
This code is working for me on API 8+, with support lib v7:

<style name="NoActionBar" parent="@style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>

set that theme for your activity:

<activity android:theme="@style/NoActionBar" ... />

and in your activity class.

It works even when it extends ActionBarActivity.

忆离笙 2024-12-27 22:06:45

如果您只想要一个没有操作栏的主题,您可以使用“NoActionBar”变体,例如。如果您的基本主题如下所示

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

,那么您可以使用

<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

但是如果您想保留主主题的属性,即AppTheme,您可以按如下方式执行

<style name="AppThemeNoActionBar" parent="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

您可以通过这种方式保留基本主题的所有属性,而不必显式添加它们在您的 NoActionBar 主题中:)

If you just want a theme with no action bar you can use 'NoActionBar' variant, for eg. if your base theme is as below

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

then you can use

<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

But if you want to retain the properties of your main theme i.e. AppTheme you can do as below

<style name="AppThemeNoActionBar" parent="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

You can retain all the properties of your base theme this way and don't have to explicitly add them in your NoActionBar theme :)

握住我的手 2024-12-27 22:06:45

res -> 下value ->styles.xml

更改

Under res -> values ->styles.xml

Change

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

To

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

所谓喜欢 2024-12-27 22:06:45

这是一个快速解决方案。

您找到 styles.xml 并将基本应用程序主题更改为“Theme.AppCompat.NoActionBar”,如下所示。

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- Customize your theme here. -->
</style>

Heres a quick solution.

You find styles.xml and you change the base application theme to "Theme.AppCompat.NoActionBar" as shown below.

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- Customize your theme here. -->
</style>
妥活 2024-12-27 22:06:45

setContentView 之前将此代码键入到 onCreate 方法中:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0);

Type this code to your onCreate method before setContentView:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0);
瀞厅☆埖开 2024-12-27 22:06:45

以下是永久隐藏操作栏的步骤:

  1. 打开 app/res/values/styles.xml。
  2. 查找名为“apptheme”的样式元素。应该看看
    类似于

  3. 现在将父主题替换为包含以下内容的任何其他主题
    名称中的“NoActionBar”。

    a.您还可以通过切换到 Activity_main.xml 的设计选项卡,然后尝试 UI 的主题下拉列表中提供的每个主题来检查主题的外观。

  4. 如果您的 MainActivity 扩展了 AppCompatActivity,请确保
    您使用 AppCompat 主题。

Below are the steps for hiding the action bar permanently:

  1. Open app/res/values/styles.xml.
  2. Look for the style element that is named "apptheme". Should look
    similar to <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">.
  3. Now replace the parent with any other theme that contains
    "NoActionBar" in its name.

    a. You can also check how a theme looks by switching to the design tab of activity_main.xml and then trying out each theme provided in the theme drop-down list of the UI.

  4. If your MainActivity extends AppCompatActivity, make sure
    you use an AppCompat theme.

明媚殇 2024-12-27 22:06:45

我想发布一个设计器方法来解决这个问题,这将使设计与您的业务逻辑分开:

步骤 1. 在 (res->values->styles.xml) 中创建新样式:基本上它是您整体的副本具有不同父级的方案-parent =“Theme.AppCompat.Light.NoActionBar”

<!-- custom application theme. -->
    <style name="MarkitTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimary</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="android:windowNoTitle">true</item>
    </style>

第2步:在您的AndroidManifest.xml中,将此主题添加到您想要的活动中:例如,我希望我的主要活动没有操作栏,因此添加如下所示:

<activity android:name=".MainActivity"
            android:theme="@style/MarkitTheme">

这在尝试了很多事情之后,这对我来说是最好的解决方案。

I would like to post rather a Designer approach to this, this will keep design separate from your business logic:

Step 1. Create new style in (res->values->styles.xml) : Basically it is copy of your overall scheme with different parent - parent="Theme.AppCompat.Light.NoActionBar"

<!-- custom application theme. -->
    <style name="MarkitTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimary</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="android:windowNoTitle">true</item>
    </style>

Step 2: In your AndroidManifest.xml, add this theme to the activity you want in: e.g. I want my main activity without action-bar so add this like below:

<activity android:name=".MainActivity"
            android:theme="@style/MarkitTheme">

This is the best solution for me after trying a lot of things.

苦妄 2024-12-27 22:06:45

在 onCreate 函数中添加以下代码

ActionBar actionBar = getSupportActionBar();
actionBar.hide();

并导入 android.support.v7.app.ActionBar

in the onCreate function add the following code

ActionBar actionBar = getSupportActionBar();
actionBar.hide();

and just import android.support.v7.app.ActionBar

鸩远一方 2024-12-27 22:06:45

确保通过将 styles.xml 文件中的默认主题名称更改为:

 <style name="MyTheme" parent="android:Theme.Material.Light.NoActionBar">

然后从 main_activity.xml 下的下拉列表中更改主题 来创建新主题code> 到你所谓的主题。

Make sure you create a new theme by changing the name of the default theme in the styles.xml file to:

 <style name="MyTheme" parent="android:Theme.Material.Light.NoActionBar">

and than change the theme from the drop-down under your main_activity.xml to whatever you called your theme.

你曾走过我的故事 2024-12-27 22:06:45

styles.xml 文件中使用它:


<style name="MyTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>

Use this in styles.xml file:


<style name="MyTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
做个少女永远怀春 2024-12-27 22:06:45

另一个有趣的解决方案是,您希望在删除操作栏的同时保留 ViewPager ,其样式为 show

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:actionBarStyle">@style/NoActionBarStyle</item>
    <item name="android:windowContentOverlay">@null</item>
</style>
<style name="NoActionBarStyle" parent="android:Widget.Holo.ActionBar">
    <item name="android:backgroundSplit">@null</item>
    <item name="android:displayOptions"></item>
</style>

这是 Android 中大多数拨号器应用程序在没有操作栏的情况下显示 ViewPager 的方式。

参考:https://github.com/CyanogenMod/android_packages_apps_Dialer

Another interesting solution where you want to retain the ViewPager while removing the action bar is to have a style as show

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:actionBarStyle">@style/NoActionBarStyle</item>
    <item name="android:windowContentOverlay">@null</item>
</style>
<style name="NoActionBarStyle" parent="android:Widget.Holo.ActionBar">
    <item name="android:backgroundSplit">@null</item>
    <item name="android:displayOptions"></item>
</style>

This is the way most of the Dialer applications in android is showing the ViewPager without the action bar.

Ref: https://github.com/CyanogenMod/android_packages_apps_Dialer

诗酒趁年少 2024-12-27 22:06:45

在你的清单中尝试这个

 <activity
        android:name=".MainActivity"
        android:theme="@android:style/Theme.Holo.NoActionBar"
        android:label="@string/app_name" >

try this in your manifist

 <activity
        android:name=".MainActivity"
        android:theme="@android:style/Theme.Holo.NoActionBar"
        android:label="@string/app_name" >
貪欢 2024-12-27 22:06:45
  protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.hide();
    }
    setContentView(R.layout.activity_main);
  protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.hide();
    }
    setContentView(R.layout.activity_main);
熟人话多 2024-12-27 22:06:45

在 Android 中禁用 ActionBar 有两种方法。

requestWindowFeature(Window.FEATURE_NO_TITLE); 
setContentView(R.layout.activity_main); 

There are two ways to disable ActionBar in Android.

requestWindowFeature(Window.FEATURE_NO_TITLE); 
setContentView(R.layout.activity_main); 
看海 2024-12-27 22:06:45

我使用这个解决方案:

在清单中,在您的活动标记内:

android:label="@string/empty_string"

和在 strings.xml 中:

<string name="empty_string">""</string>

这样您就可以将 ActionBar (或工具栏)与标题保持在一起,但是当创建 Activity 时,标题会自动为空。

I use this solution:

in the manifest, inside your activity tag:

android:label="@string/empty_string"

and in strings.xml:

<string name="empty_string">""</string>

This way you keep ActionBar (or Toolbar) with the title, but when Activity if created the title is automatically empty.

上课铃就是安魂曲 2024-12-27 22:06:45

奇怪的是,当我在运行 4.4.2 (API 19) 的 Nexus 7 上构建时,这些都不起作用。在大多数情况下,至少在使用最新版本的 Android Studio (1.2.1.1) 创建空白活动应用程序后,:

android:theme="@style/AppTheme"

位于应用程序元素中,而不是活动元素中。如果我删除上面的代码或尝试将其更改为:

android:theme="@android:style/Theme.Holo.Light.NoActionBar"

应用程序将无法运行...如果这种情况发生在您身上,只需进入您的 styles.xml 文件(res > value > styles .xml)并将 .NoTitleBar 添加到父级的末尾,如下块:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>

不需要对 AndroidManifest 文件进行任何更改。

Strangely enough, none of these worked for me when building on a Nexus 7 running 4.4.2 (API 19). For the most part, at least with the latest version of Android Studio (1.2.1.1) after creating a blank activity app, the:

android:theme="@style/AppTheme"

is in the application element, not the activity element. If I removed the above code or tried to change it to:

android:theme="@android:style/Theme.Holo.Light.NoActionBar"

the app won't run...if this is happening to you, just go into your styles.xml file (res > values > styles.xml) and add the .NoTitleBar to the end of the parent like this block:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>

No changes to the AndroidManifest file are needed.

逆光飞翔i 2024-12-27 22:06:45

在您的 activity_main.xml 中,您可以从那里进行调整
行中:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
.......
    android:theme="@style/Theme.Design.Light.NoActionBar"
.......    
">

有时当你看到这样的东西点击这里,你可以从这里选择“noActionBar”主题。

希望我对你有帮助。

In your activity_main.xml, you can adjust from there
in the line:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
.......
    android:theme="@style/Theme.Design.Light.NoActionBar"
.......    
">

Sometimes when you can see things like this Click here, You can select from here the "noActionBar" theme.

Hope me helped you.

对风讲故事 2024-12-27 22:06:45

一些答案已经写好了,如果您在 res>values 中没有找到 styles.xml 文件,那么您可以转到 res>values>themes>; theme.xml 这里你需要在样式中添加这两行

 <item name="android:windowFullscreen">true</item>
 <item name="windowNoTitle">true</item>

Some answers already been written and if you didn't find styles.xml file in res>values then you can do this go to res>values>themes>themes.xml here you need to add these two lines inside the style

 <item name="android:windowFullscreen">true</item>
 <item name="windowNoTitle">true</item>
筱果果 2024-12-27 22:06:45

Theme.xml 文件

 <style name="Theme.FurnitureApp.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
    </style>

在 setContent{ } 方法之前写入以下代码

requestWindowFeature(Window.FEATURE_NO_TITLE);
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0)

Theme.xml file

 <style name="Theme.FurnitureApp.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
    </style>

write the below code before setContent{ } method

requestWindowFeature(Window.FEATURE_NO_TITLE);
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文