所以我完成了我的应用程序并进行了最终测试。在Android 5.0 +上,它运行良好,但在棒棒糖之前的设备上,我遇到了奇怪的错误。
起初,操作栏在带有ScrollView
的活动中不可见,我通过将ScrollView
放入RelativeLayout
中来修复它。但这只能解决一半的问题。 Action bar
颜色是透明的,我可以分辨出来,因为我的活动的背景颜色是#f2f2f2
的,Action bar
上的文字是白色的。
看到操作栏标题,后退按钮和我放在操作栏中的所有图像,但无法将其颜色设置为ColorPrimary
,即材料浅蓝色。
这是活动代码(不是内容)
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="hr.app.liftme.liftmehr.VjezbeTricepsTricepsEkstenzijaKablovima">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
android:elevation="10dp"
app:elevation="10dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_vjezbe_triceps_triceps_ekstenzija_kablovima" />
</android.support.design.widget.CoordinatorLayout>
这是我声明的java文件
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vjezbe_triceps_triceps_ekstenzija_kablovima);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
谁能帮我解决这个问题?
>/** 在您的 xml,颜色/背景中,根据您的要求更改 **/
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="55dp"
android:padding="@dimen/appbar_padding"
android:background="@color/appbarColor">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/place_order"
android:layout_gravity="center"
android:textSize="@dimen/appbar_txt_size"
android:textStyle="bold"
android:textColor="@color/white"
android:layout_marginTop="15dp"
android:id="@+id/toolbar_title"/>
</android.support.v7.widget.Toolbar>
/** 在你的 java 文件中 **/
toolbar.setBackgroundColor(Color.parseColor("#617191"));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getActivity().getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(getActivity().getResources().getColor(R.color.toolbar));
}