What is the alternative to getActionBar ()?

When I try to use getActionBar(), it says that it is out of date, so this means that, moving forward, we are not allowed to use getActionBar().

What is the best way to learn how to create tabs in the current situation?

+1
source share
2 answers

The reason you should create this is because the fragment tabs using the ActionBar is now deprecated. This is a new way to create your action bar using Material Design. for this you need to add the dependencies in the build.gradle file.

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

create the toolbar file app_bar.xml, you can specify 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"
/>

Make sure you select a theme in styles.xml with

"Theme.AppCompat.NoActionBar"

mainActivity.xml, ,

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

MainActivity . , setContentView()

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

appcompat, getSupportActionBar()

+3

All Articles