Create themes in the Android app

Asked

Viewed 82 times

0

Guys, it is possible to customize the color of the action bar on Android, because I’m developing an application and I wanted users to be able to choose the color of the application they like best. Does anyone know if it is possible to do this with appcompat.

  • It is possible yes, and there are several ways to do this. Cool would be to make a gridview with various colors. This way, as long as the user chooses a color, the theme changes accordingly.

1 answer

2


If you use a Toolbar, yes. she’s in the library appcompat-v7 and you must 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 should be the type AppCompatActivity or ActionBarActivity:

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);
  • Got it, thanks for the suggestion, soon I will post on github the solution.

Browser other questions tagged

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