我想将图像置于我的操作栏上 . 所以这里......
这是我的 actionbar_about.xml 文件 . 在这个xml文件中是图像所在
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/about_actionbar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:src="@drawable/ic_about" />
</RelativeLayout>
这是我将覆盖或膨胀该xml文件的地方 . AboutUs.java . 这个't mainactivity.java that'为什么我在使用 getActivity()
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ActionBar
ActionBar mActionBar = getActivity().getActionBar();
mActionBar.setDisplayShowHomeEnabled(true);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(getActivity());
View mCustomView = mInflater.inflate(R.layout.actionbar_about, null);
ImageView mImageView = (ImageView) mCustomView.findViewById(R.id.about_actionbar);
mImageView.setImageDrawable(getResources().getDrawable(R.drawable.ic_about));
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
}
多谢你们! :)
1 回答
你可以试试这个 .