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);