I'm using getSupportActionBar().setIcon(R.drawable.ic_transparent);
to set the icon of my toolbar. How do I get the ImageView
from that icon? I need the Rect
of the icon.
I'm trying to implement a version of this with a Toolbar
instead of the old action bars.
EDIT: I came up with an alternate solution that puts a TextView and an ImageView in the toolbar instead of using the built in logo and title. This works fine on Android 5.0, but the text doesn't show up on anything below that. Any suggestions to fix either this or the above?
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@android:color/transparent"
android:elevation="10dp"
tools:ignore="UnusedAttribute">
<ImageView
android:id="@+id/toolbar_icon"
android:layout_width="?android:attr/actionBarSize"
android:layout_height="?android:attr/actionBarSize"
android:padding="10dp"
android:scaleType="fitStart"
android:src="@drawable/ic_transparent" />
<TextView
android:id="@+id/toolbar_title"
style="@style/Base.TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="hello" />
</android.support.v7.widget.Toolbar>