本文介绍了如何添加的ImageView上的操作栏右侧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要添加图像视图的操作栏右侧side.I想这样做,但我不能。谁能帮我?
I want to add image view on action bar right hand side.I tried to do that but i couldn't.Can anyone help me?
这是我的形象认为XML
This is my image view xml
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/adnace_search_i" />
这是行动起来吧,我想创造的形象。
This is the image of action bar that i want to create.
推荐答案
试试这个...
ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(actionBar.getDisplayOptions()
| ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView imageView = new ImageView(actionBar.getThemedContext());
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setImageResource(R.drawable.adnace_search_i);
ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT, Gravity.RIGHT
| Gravity.CENTER_VERTICAL);
layoutParams.rightMargin = 40;
imageView.setLayoutParams(layoutParams);
actionBar.setCustomView(imageView);
这篇关于如何添加的ImageView上的操作栏右侧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!