Create themes in the Android app

0

People, it is possible to customize the color of the action bar on Android, because I am developing an application and I wanted the users to choose the color of the application that they like. Does anyone know if it is possible to do this with appcompat.

    
asked by anonymous 11.10.2016 / 16:17

1 answer

2

If you use Toolbar , yes. it is in the appcompat-v7 library and you should choose the NoActionBar theme for the app:

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    </style>

Insert a Toolbar into your xml layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/toolbar_height"
    android:background="@color/colorPrimary"
    app:titleTextColor="@android:color/white">
</LinearLayout>

Now in Activity, identify the Toolbar:

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

Remembering that Activity must be AppCompatActivity or ActionBarActivity type:

public class MeuActivity extends ActionBarActivity

Now your Toolbar is a View like any other. You can change the background color using:

int corVerde = Color.parseColor("#50a600");
toolbar.setBackgroundColor(corVerde);
    
11.10.2016 / 16:26