什么是替代getActionBar()? [英] What is the alternative to getActionBar()?

查看:125
本文介绍了什么是替代getActionBar()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 getActionBar()它说,这是德precated,这样就意味着通过展望未来,我们不允许使用 getActionBar()

When I try to use getActionBar() it says it is deprecated, so that means by going forward we are not allowed to use getActionBar().

这就是学习如何在当前形势下创建标签的最佳方式?

Which is the best way to learn how to create Tabs in the current situation?

推荐答案

您应该创建这样做的原因,是因为片段标签使用 动作条现在是很precated。这是全新的方式与创建动作条 材料设计。你需要在你的build.gradle文件中添加依赖使用此功能。

The reason you should create this, because Fragment Tabs using ActionBar is now deprecated. This is new way to create your actionbar with Material Design. to use this you need to add dependencies in your build.gradle file.

compile 'com.android.support:appcompat-v7:21.0.0'

创建工具栏app_bar.xml文件,你可以给你想要的名字。

create toolbar app_bar.xml file, you can give the name you want.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

请确保你选择的主题styles.xml与

Make sure, you selected theme in styles.xml with

"Theme.AppCompat.NoActionBar"

在这之后,你需要初始化这个工具栏在你的mainActivity.xml布局文件,包括这个,

after that, you need to initialize this toolbar in your mainActivity.xml layout file, for that include this,

 <include
        android:id="@+id/app_toolbar"
        layout="@layout/app_toolbar"/>

然后在MainActivity,你需要使工具条工具栏的实例。那么,以后的setContentView() 加在与你的

then in the MainActivity, you need to make instance of Toolbar toolbar. then, after setContentView() add following with your

 toolbar = (Toolbar) findViewById(R.id.app_toolbar);
    setSupportActionBar(toolbar);

这篇关于什么是替代getActionBar()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆