我从style.xml覆盖ActionBar的BackGround颜色 这是代码:
<?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>
主要活动的代码在这里:
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);
}
问题是如果我从style.xml设置颜色,我看不到操作栏的文本。此外,我不能使用像:
这样的东西<item name="android:textColorPrimary">@color/row_child_menu_title</item>
或
<item name="android:colorAccent">@color/row_child_menu_title</item>
结果是一样的。文本正在消失,只有菜单图标和切换图标可见
提前致谢
答案 0 :(得分:0)
<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" >
活动:
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("title");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);