How to add the Toolbar in Activity without inheriting AppCompatActivity - Android Studio 1.4

0

Good evening.

I upgraded my Android Studio to version 1.4 and by default, any% created% uses as inheritance activity AppCompatActivity . I developed an app that needs to inherit a class responsible for controlling the lifecycle of each (public class MainActivity extends AppCompatActivity) as in the following example: activity . The problem is that by doing this, the project name does not appear in public class MainActivity extends LifeCycleActivity when running the app. Since updating toolbar brought two layouts ( Android Studio and content_main.xml ) to each activity_main.xml , I'd like to know if I solve the problem of displaying the project name in activity through the layout files themselves, or through code, since I'm not using toolbar as an inheritance.

    
asked by anonymous 16.10.2015 / 04:44

3 answers

-1

I followed the help I got and the solution was solved by making the class LifeCycleActivity inherit from AppCompatActivity .

    
30.10.2015 / 13:07
0

When we create ActionBar without AppCompatActivity you need to define the ActionBar layout in your xml. Put the code below as the first element of your layout.xml

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="@color/colorPrimary"
    android:elevation="6dp"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    />

Next, place the following in the respective Activity (in the onCreate method):

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTittle("titulo");

I hope I have helped

    
19.05.2016 / 15:43
-1

Just set up the toobar title.

Toolbar toobar  = (Toolbar)findViewById(R.id.toobar);
setSupportActionBar(toolbar);
toolbar.setTitle("seu título");
    
16.10.2015 / 04:55