Moin Khan Moin Khan -3 years ago 121
Android Question

How to show the imageview in right hand side edge(i.e) before the logout icon?

I want to show profile picture on Action Bar just before logout icon but its showing the image just after the App title. I have used Image View and Picasso for load image from server using volley. How can achieve this ?

actionBar.setDisplayOptions(actionBar.getDisplayOptions()
| ActionBar.DISPLAY_SHOW_CUSTOM);

imageView.setScaleType(ImageView.ScaleType.CENTER);
Picasso.with(HomeActivity.this).load(AppConfig.profilePic + image).placeholder(R.drawable.profile).transform(new CircleTransform()).fit().into(imageView);
ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT, Gravity.RIGHT
| Gravity.CENTER_VERTICAL);
layoutParams.gravity = Gravity.RIGHT;
imageView.setLayoutParams(layoutParams);
actionBar.setCustomView(imageView);


enter image description here

Answer Source

this can not be done there as its standard to show title first Solution >> use custom action bar 1- build your own layout 2- change the theme to NoAction bar for your app in style file 3- use include to add your custom actionBar to any layout you want

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_scrollFlags="scroll|enterAlways"
    app:layout_collapseMode="pin">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/toolbar_logo"
            android:src="@drawable/logo"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginRight="?attr/actionBarSize"
            android:layout_marginTop="4dp"
            android:layout_marginBottom="4dp" />

        <TextView
            android:id="@+id/toolbar_title"
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginRight="?attr/actionBarSize"
            android:layout_gravity="center"
            android:gravity="center_vertical"
            android:visibility="gone"
            android:text="@string/app_name"
            android:textColor="@color/white"
            style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
            />


    </FrameLayout>
</android.support.v7.widget.Toolbar>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download