如何将图标移动到右上角?

时间:2015-11-15 15:09:52

标签: android image android-studio icons

我试图在android studio的右上角创建一个图标,除了声明字之外。它应该如下图所示:

enter image description here

Claims1.java

 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = this.getArguments();
        fk = bundle.getLong("ab");
        View claims = inflater.inflate(R.layout.claims, container, false);
        mDrawerLayout = (DrawerLayout)claims.findViewById(R.id.drawer_layout);
        android.support.v7.app.ActionBar myActionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
        ImageView imageView = new ImageView(myActionBar.getThemedContext());
        imageView.setScaleType(ImageView.ScaleType.CENTER);
        imageView.setImageResource(R.mipmap.create);
        android.support.v7.app.ActionBar.LayoutParams layoutParams = new android.support.v7.app.ActionBar.LayoutParams(
                android.support.v7.app.ActionBar.LayoutParams.WRAP_CONTENT,
                android.support.v7.app.ActionBar.LayoutParams.WRAP_CONTENT, Gravity.RIGHT
                | Gravity.CENTER_VERTICAL);
        layoutParams.rightMargin = 40;
        imageView.setLayoutParams(layoutParams);
        myActionBar.setCustomView(imageView);
        return claims;
    }

claims.xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <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="@mipmap/create" />

</android.support.v4.widget.DrawerLayout>

但是我只能得到这个。

enter image description here

任何人都可以提供帮助?感谢

1 个答案:

答案 0 :(得分:0)

1。添加

2

'spospo' setHasOptionsMenu(true); 方法中的

2。使用您的菜单在OnCreate下创建Fragment

my_menu.xml

3。 \res\menu方法 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:icon="@drawable/YOURICONHERE" android:id="@+id/YOURIDHERE" android:orderInCategory="100" android:title="YOURTITLE" app:showAsAction="always" /> </menu>

Override