2015-03-31 66 views
0

我試圖通過在左側添加一個自定義後退按鈕和中心的圖標來設置動作欄的樣式。 Android Studio中的渲染與我想要的完全一樣,但是當我在手機上測試佈局時,它只顯示左側的後退按鈕和圖標,後退按鈕頂部的圖標。這是我的佈局文件:設計動作欄的樣式

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:id="@+id/action_bar_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ImageButton android:id="@+id/back_button" 
     android:contentDescription="Image" 
     android:src="@drawable/back_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:background="@color/action_bar_bg_color" 
     android:layout_alignParentLeft="true"/> 

    <ImageView android:id="@+id/cow_icon" 
     android:contentDescription="Image" 
     android:src="@drawable/cowhead" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_centerVertical="true"/> 

</RelativeLayout> 

這是我做什麼樣式的操作欄:

ActionBar actionBar = getSupportActionBar(); 
    actionBar.setDisplayShowTitleEnabled(false); 
    View mActionBar = getLayoutInflater().inflate(R.layout.action_bar_layout, null); 
    actionBar.setCustomView(mActionBar); 
    actionBar.setDisplayShowCustomEnabled(true); 

任何人看到這可能是造成操作欄的有缺陷的造型?

回答