Android上的双工具栏

时间:2016-02-29 15:15:32

标签: android toolbar

我想要像这样实现android双工具栏:

andorid

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="@dimen/abc_action_bar_default_height_material"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:background="@color/PrimaryColor" >
    <ImageView
        android:layout_width="wrap_content"
        android:contentDescription="ManUtdLogo"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/manutdtoolbar_logo"/>
</android.support.v7.widget.Toolbar>

这是我的预览工具栏:

enter image description here

我尝试新代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="@dimen/abc_action_bar_default_height_material"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:background="@color/PrimaryColor" >
    <ImageView
        android:layout_width="wrap_content"
        android:contentDescription="ManUtdLogo"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/manutdtoolbar_logo"/>
</android.support.v7.widget.Toolbar>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:background="@color/SecondColor">
    </LinearLayout>
</android.support.design.widget.AppBarLayout>

但结果给了我一个错误:

02-29 21:33:07.880 2039-2039/com.studio.erlangga.manutd I/art: Not late-enabling -Xcheck:jni (already on) 02-29 21:33:07.960 2039-2039/com.studio.erlangga.manutd I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead. 02-29 21:33:08.060 2039-2054/com.studio.erlangga.manutd D/OpenGLRenderer: Render dirty regions requested: true 02-29 21:33:08.100 2039-2039/com.studio.erlangga.manutd D/Atlas: Validating map... 02-29 21:33:08.160 2039-2054/com.studio.erlangga.manutd I/OpenGLRenderer: Initialized EGL, version 1.4 02-29 21:33:08.200 2039-2054/com.studio.erlangga.manutd D/OpenGLRenderer: Enabling debug mode 0 02-29 21:33:08.220 2039-2054/com.studio.erlangga.manutd W/EGL_emulation: eglSurfaceAttrib not implemented 02-29 21:33:08.220 2039-2054/com.studio.erlangga.manutd W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f0186ac4c80, error=EGL_SUCCESS 02-29 21:33:13.710 2039-2042/com.studio.erlangga.manutd W/art: Suspending all threads took: 10ms 02-29 21:34:09.410 2039-2039/com.studio.erlangga.manutd W/art: Before Android 4.1, method int android.support.v7.internal.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView 02-29 21:34:09.490 2039-2054/com.studio.erlangga.manutd W/EGL_emulation: eglSurfaceAttrib not implemented 02-29 21:34:09.490 2039-2054/com.studio.erlangga.manutd W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f017e4caac0, error=EGL_SUCCESS 02-29 21:34:10.730 2039-2039/com.studio.erlangga.manutd W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.

我希望最终结果是这样的:

enter image description here

任何人都可以帮助我....谢谢

1 个答案:

答案 0 :(得分:0)

使用这种textView:

<TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" //or 50dp
        android:text="Home"
        android:textColor="#EEEEEE" //white
        android:textSize="20sp"
        android:background="#000000" //black
        android:gravity="center_vertical"/>

要更改文本,请在您的活动中使用:

TextView title = (TextView) findViewById(R.id.title);
title.setText("New text");