2016-02-29 79 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");