2016-02-29 156 views
-1

我想实现的Android双工具栏是这样的:双工具栏上的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

只需创建一个LinearLayout中,并不需要是一个工具栏 – Chol

+0

使用custome布局,而不是 –

+0

是黑的“家”酒吧应该可点击吗? – CaptJak

回答

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");