2015-03-31 63 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); 

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

回答