Android - a double window with an indicator for the selected list item

In my application, I have a two-pane layout with a list on the left side. I would like to add an indicator to the right of the selected list line, as in the following examples:

Gmail exampleReader example

I assume this is a built-in function, but I could not find any documentation on it. Does anyone know how we implement this?

+4
source share
3 answers

Despite the code, I could not say for sure, but I am pretty sure that the indicator is not a built-in function. It may be a custom view, but most likely they just set the composite form as described here: BitmapDrawable and here: TextView

The method you are looking for is setCompoundDrawables ().

0
source

On top of my head, I would simply add an indicator that matches the color of the right side background, which makes it smooth. A simple solution.

0
source

An easy way to do this is to use a 9-patch image . For example, if you want to reproduce the double-window effect with Theme.DeviceDefault.Light (API> 14), use the Selector to apply a background image with 9 patches in the selected state of your LinearLayout element.

An example of selecting the layout of an element:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="48dp" android:background="@drawable/activable_indicator_background" android:gravity="center_vertical" android:paddingRight="20dp"> //eventually other items... </LinearLayout> 

Drawable/activable_indicator_background.xml :

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_activated="true" android:drawable="@drawable/indicator" /> <item android:drawable="@android:color/transparent" /> </selector> 

Drawable/indicator.9.png :

Indicator 9-patch image

0
source

Source: https://habr.com/ru/post/1437629/


All Articles