我想在注销图标之前在操作栏上显示个人资料图片,但它在应用程序标题之后显示图像。我已经使用 Image View 和 Picasso 来使用 volley 从服务器加载图像。如何实现这一目标?
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);
最佳答案
这不能在那里完成,因为它的标准是首先显示标题 解决方案 >> 使用自定义操作栏 1-建立自己的布局 2- 在样式文件中将您的应用程序的主题更改为 NoAction 栏 3- 使用 include 将您的自定义 actionBar 添加到您想要的任何布局
<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>
关于android - 如何在注销图标之前的右侧边缘(即)显示 ImageView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45706494/