Issue
How do I make a basic icon button without text or background? For example, just a simple vector image from @drawables that, when clicked, shows that circular response thing around it. I don't want the icon to have any background color to it. Just an icon that can be clicked, that's literally it.
I can only figure out how to do it by creating a menu
and setting the icon as an item
with app:showAsAction="always"
. It seems like there must be a better way to do this.
Edit: Here's an example of what I want to achieve. It's very basic. Just a clickable icon with responsive feedback when touched. https://material-ui.com/components/buttons/#icon-buttons
It's exactly the same as creating the following. I just thought there was likely an easier way to do this without having to create and load a menu just for one single icon:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.mycompany.myapp.MainActivity">
<item
android:id="@+id/action_contacts"
android:icon="@drawable/ic_contacts_24"
android:title="@string/action_contacts"
app:iconTint="@android:color/white"
app:showAsAction="always" />
</menu>
Solution
First create a
vector drawable
and then add to theImageView
like this:
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
app:srcCompat="@drawable/ic_delete" />
Answered By - Sumit Shukla
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.