2015-01-08 35 views
-4

我是一名新的Android開發人員。如何在actionbar android中設置背景圖片。如何在actionbar中設置背景圖像android

我可以在我的操作欄中添加圖像背景。但不能縮放我的圖像。

enter image description here

我的風格

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 

</style> 

MainActivity

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    LayoutInflater mInflater = LayoutInflater.from(this); 

    View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null); 

    ActionBar actionBar = getSupportActionBar(); 
    actionBar.setDisplayShowHomeEnabled(true); 
    actionBar.setDisplayShowTitleEnabled(false); 
    actionBar.setDisplayShowCustomEnabled(true); 
    actionBar.setCustomView(mCustomView); 

} 

custom_actionbar佈局

<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> 
<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:src="@drawable/image" /> 
</RelativeLayout> 

解決方案

我使用這個庫>>Android-ObservableScrollView

回答

1

請閱讀這篇文章:http://cyrilmottier.com/2013/05/24/pushing-the-actionbar-to-the-next-level/

那裏你會找到例子和教程你questuion

,你也可以像這樣設置動作欄背景。

private void setActionBar() { 
     getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
     getSupportActionBar().setHomeButtonEnabled(true); 
     getSupportActionBar().setDisplayShowHomeEnabled(true); 
     getSupportActionBar().setCustomView(R.layout.header_actionbar); 
     getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionbar_blue))); 
     TextView tvHeader = (TextView) findViewById(R.id.tv_title_header_actionbar); 
     TextView tvSubheader = (TextView) findViewById(R.id.tv_subtitle_header_actionbar); 
     tvSubheader.setVisibility(View.GONE); 
    } 

通話setActionBar()oncreate()