Issue
I am new to Android dev and kindly asking for help.
I would like to make "settings-like" (full-width, flat, with images, with separators) button in my app. Here is the example: Example image from Samsung settings app
I know about "Preference" view - it is not the solution. Is there any native view for this type of button? If not, what is the most appropriate way to make this button possible?
Upd.: I have managed to make the buttons by myself using LinearLayout. You can find my implementation in answers below.
Solution
Ok, seems there is no native view for this type of button in Android.
RecyclerView and ListView will not help, because they require adapters (I have no need in adapters, I need simple buttons only).
So, I decided to make these buttons using linear layout, here is the code:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:padding="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_sim_card" />
<Space
android:layout_width="16dp"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/action_edit" />
</LinearLayout>
Make LinearLayout
android:clickable="true"
and
android:focusable="true"
(later you can just bind onClickListener in code) for it will act like a button. And the main point is to make button-like animations (ink-effect on click) - specify background attribute:
android:background="?android:attr/selectableItemBackground"
Answered By - Imajou
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.