本文介绍了如何显示和隐藏动作条与AppCompat V.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序,显示文本。

I have a simple app that displays text.

该应用程序开始的几个选项的主屏幕(例如,一个信息键,导致有关的应用程序,一个浏览按钮,允许用户看到文本的所有的单个小片​​可以显示信息)。主按钮导致其中显示文本另一个屏幕。刷卡左,右,他能看到不同的文本段落。这是该应用的主要目的

The app starts with a main screen with a few options (ex. an info button that leads to info about the app, a browse button that allows the user to see all the individual pieces of text that can be displayed). The main button leads to another screen where text is displayed. By swiping left and right he can see different passages of text. This is the main purpose of the app.

目前我有一个动作条执行。我MainActivity.Java延伸AppCompatActivity。在应用程序的一切都是本次活动。

Currently I have an ActionBar implemented. My MainActivity.Java extends AppCompatActivity. Everything in the app is in this activity.

现在我想让它这样的动作条只出现在显示模式,而不是在启动画面,或信息/浏览模式。

Now I want to make it so the ActionBar appears only in "Display" mode, not in the start up screen, or "info" / "browse" mode.

是否有可能在应用程序的一部分的动作条,而没有的动作条的应用程序的其他部分? (并保持它都在同一个活动?)

Is it possible to have an ActionBar in one part of the app, and no ActionBar in another part of the app? (And keep it all in the same activity?)

我一直在试图做到这一点收效不大。如果这是可能的,我应该尝试下?

I've been trying to accomplish this without avail. If this is possible, what should I try next?

到目前为止,我已经尝试了以下内容:

So far, I've attempted the following:

1)创建这个主题

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

和其应用到MainActivity ...

And apply it to MainActivity ...

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

....这样做后,在动作条仍然存在。 (这源于此SO职位(安卓windowNoTitle不会隐藏动作条与appcompat-V7 21.0.0

....After doing this, the ActionBar was still there. (This comes from this S.O. post (android:windowNoTitle will not hide actionbar with appcompat-v7 21.0.0)

2)另一种尝试是把它添加到的onCreate。

2) Another attempt was to add this to onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    getActionBar().hide();

    setContentView(R.layout.activity_main);

这是来自研究这个S.O.职位:(?如何隐藏操作栏活动创建之前,然后再次显示它

This came from studying this S.O. post: (How to hide action bar before activity is created, and then show it again?)

有什么建议?

推荐答案

在那里,你想有活动的没有的操作栏使用源自一个主题 Theme.AppCompat.NoActionBar Theme.AppCompat.Light.NoActionBar 。这一活动将永远无法显示操作栏,除非你提供你自己通过 setSupportActionBar(工具栏)

In the activities where you want to have no action bar use a theme derived from Theme.AppCompat.NoActionBar or Theme.AppCompat.Light.NoActionBar. This activity will never be able to show the action bar unless you supply your own via setSupportActionBar(Toolbar).

在活动,你想有动作条使用来自 Theme.AppCompat 导出一个主题,主题.AppCompat.Light Theme.AppCompat.Light.DarkActionBar 。这将允许你动态地隐藏或显示此类活动的操作栏。您将无法使用这些主题来提供你自己的行动吧。

In the activities where you want to have the action bar use a theme derived from Theme.AppCompat, Theme.AppCompat.Light or Theme.AppCompat.Light.DarkActionBar. This will allow you to dynamically hide or show the action bar in such activity. You will not be able to supply your own action bar using these themes.

与appcompat-V7行动酒吧工作您需要通过调用 getSupportActionBar()而不是 getActionBar获得它()

When working with appcompat-v7 action bar you need to obtain it by calling getSupportActionBar() instead of getActionBar().

这篇关于如何显示和隐藏动作条与AppCompat V.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 04:30