How to add an ActionBar / ToolBar in Android 2.2 project? [duplicate]

1

I have a project / app developed in Android 2.2. The same runs without any problem, but as the current devices are abolishing the menu button or in some cases use virtual buttons, it becomes "poor" if it is installed on some devices that do not have the button. I would like to know how I can implement an ActionBar / ToolBar for this project / app in the simplest way possible, ie I do not want to have to make big changes to the code.

Thank you all and I look forward to any help.

Ps: My application already exists, so I do not know how to include such a "feature" in it.

    
asked by anonymous 17.10.2015 / 20:14

1 answer

0

Toobar code in your xml:

    <android.support.v7.widget.Toolbar
        android:id="@+id/toobar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:popupTheme="@style/Theme.AppCompat.Light"
        android:background="@color/colorPrimary"
        android:elevation="3dp"
        />

In the activity class:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.seuLayout);
        toobar = (Toolbar)findViewById(R.id.toobar);
        setSupportActionBar(toobar);
}

In styles.xml:

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorPrimary</item>       
 </style>
    
18.10.2015 / 00:22