2013-04-27 132 views
0

我使用sherlocklibrary在我的应用程序中显示操作栏,它工作正常,但是当我为标题添加背景图像时黑色区域出现在右侧(请参阅快照)。 如何更改菜单按钮的背景色或至少填充父页眉图像。 而且我在运行时根据用户选择更新此映像。 enter image description here 这是我的标题栏布局。更改sherlock操作栏菜单项背景颜色android

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/headerLinear" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    > 


    <ImageView 
     android:id="@+id/logo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     /> 

    <TextView 
     android:id="@+id/title" 
     style="@style/titleStyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_toLeftOf="@+id/logo" 
     android:maxLength="30" 
     android:ellipsize="end" 
     android:text="@string/login_en" /> 

</RelativeLayout> 

,我把这个代码在我的活动:

  BitmapDrawable bg = (BitmapDrawable) getResources().getDrawable(R.drawable.bg_striped_split); 

    getSupportActionBar().setBackgroundDrawable(bg); 

    LayoutInflater inflater = LayoutInflater.from(this); 
    View customView = inflater.inflate(R.layout.title_bar, null); 

    RelativeLayout header = (RelativeLayout) customView.findViewById(R.id.headerLinear); 



    header.setBackgroundDrawable(R.drawable.header); 

回答

0

我尝试这样做,它从右侧取出黑色区域的外观.. 检查的完整代码here

 getSupportActionBar().setDisplayShowHomeEnabled(false); 
     getSupportActionBar().setDisplayShowTitleEnabled(false); 
     // ActionBar actionBar = getSupportActionBar(); 
     getSupportActionBar().setCustomView(R.layout.actionbar_top); // load 
                     // your 
                     // layout 
     getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 

图片

enter image description here