[英]How to change the Text color of the action Bar using Material Theme
I override the BackGround Color of the ActionBar from the style.xml This is the code:我从 style.xml 覆盖了 ActionBar 的背景颜色 这是代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:statusBarColor">@color/ColorPrimaryDark</item>
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- Action bar -->
<style name="MyActionBar" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:background">@color/ColorPrimary</item>
</style>
</resources>
The code from main activity is here :主要活动的代码在这里:
public class MainActivity extends Activity {
private ActionBar mActionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTitles = firstItem.getTitle(); //setting the title of the first item
/**
* Action Bar customization
*/
mActionBar = getActionBar();
//Latest
mActionBar.setTitle(" Latest"); // set the first title
mActionBar.setDisplayHomeAsUpEnabled(true); // Enabling action bar app icon and behaving it as toggle button
mActionBar.setDisplayShowHomeEnabled(false); // hide tha app icon from the action bar
mActionBar.setHomeButtonEnabled(true);
}
The problem is that I can't see the text of the action bar if i set the color from style.xml .问题是如果我从 style.xml 设置颜色,我看不到操作栏的文本。 Futhermore i can't use things like :
此外,我不能使用以下内容:
<item name="android:textColorPrimary">@color/row_child_menu_title</item>
or或者
<item name="android:colorAccent">@color/row_child_menu_title</item>
the result is the same.结果是一样的。 The text is being disappeared and only the menu icons and the toggle icon are visible
文本正在消失,只有菜单图标和切换图标可见
Thanks in advance提前致谢
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#ff9501"
app:popupTheme="@style/AppTheme.PopupOverlay" >
Activity:活动:
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("title");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.