Reputation:
I am developing an android app and I want to make the title of the toolbar white color.
I have removed the default toolbar and added a toolbar to my activities and am unable to figure out how to change the color of the title of the toolbar to white
MainActivity.java
package com.example.acer.videoapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(getResources().getString(R.string.app_name));
//toolbar.setTitleTextColor(white);
listView = (ListView) findViewById(R.id.listView);
ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_expandable_list_item_1,getResources().getStringArray(R.array.subjects));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int i, long id) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("Subject", listView.getItemAtPosition(i).toString());
startActivity(intent);
}
});
listView.setAdapter(mAdapter);
}
}
Upvotes: 1
Views: 5347
Reputation: 1363
Very simple, this worked for me (white title and icon):
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/PrimaryColor"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp" />
Upvotes: 1
Reputation: 131
Set the color of the Toolbar
text using toolbar.setTitleTextColor()
method
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(getResources().getString(R.string.app_name));
toolbar.setTitleTextColor(getColor(R.color.white));
Upvotes: 1
Reputation: 1122
Modify your styles.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/white</item>
</style>
</resources>
Then assign the style to your toolbar
<android.support.v7.widget.Toolbar
...
app:theme="@style/MyTheme">
</android.support.v7.widget.Toolbar>
Upvotes: 1