How to add an Actionbar/Toolbar to an Android 2.2 project?

Asked

Viewed 1,868 times

1

I have a project/app developed on 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 became "disabled" if installed on some devices that do not have the said button. I would like to know how I can implement an Actionbar/Toolbar for this project/app as simply as possible, that is, I would not like to have to make major changes to the code.

Thank you all and look forward to any help.

Ps.: My application already exists, so I don’t know how to include such "resource" in it.

1 answer

0

the 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 class of Activity:

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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.