2015-01-08 37 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()