Insert vertical bar in list element - android

I need to insert vertical bar inside an element list.
The vertical bar must be change color in according to the type of element,
is that possible?
I show this in the image:

Yes, it is possible.
The easiest way to do it would be to simple add a View with a background color in your row layout.
Something like this would achieve the desired behavior:
XML layout
<View
android:id="#+id/color_bar"
android:layout_width="16dp"
android:layout_height="match_parent" />
In Kotlin (perhaps a RecyclerView adapter):
val colorBar = findViewById(R.id.color_bar)
val color = ContextCompat.getColor(context, R.color.your_color_here)
colorBar.setBackgroundColor(color)

You can also use a cardview and edit its background in the drawable folder

Related

How to get drawable divider between Grid View Rows?

i want to know if there is any way to display a drawable file in between the grid view rows ?(only rows) I want to get the layout in the following way
i used grid view to display books and i have divider in drawable folder and i need to show it in the that way
i searched a lot but every thing just says how to give color divider between rows but i need to display the divider from drawable
is there any way to do it?
You can define custom divider, check code snippet below:
<GridView android:layout_width="wrap_content"
android:divider="#drawable/divider"
android:dividerHeight="3sp"
android:layout_height="wrap_content" />
where divider is your custom drawable image. You can also check this link for more clarification:
custom divider

Apply style to every child view

I have the following pseudo layout:
<RelativeLayout>
<ACustomView />
<AnotherCustomView />
</RelativeLayout>
I have TextViews in both of the custom views (inflated from XML). How can i set
style properties (eg. textColor) for every TextView in the first custom view? For example i want every TextView to be red which are in the first custom view.
I don't think that this is possible.
If you don't want to much typing you can define your own style and add it to each textview or you can create your own textview class where style attributes are set.
For an example use this question/answer:
Setting global styles for Views in Android
I hope i could help you
Cu
JackZ

Android: ListView xml layout not showing background image when scrolled

I have an Activity with a ListView, I set the background image to the view programatically.
When I scroll down my list, the background image turns to white ( because my theme is Theme.Light.NoTitleBar).
How can I make it scroll with the blue background intact?
If the above point works, how can I change the text color of ListView to white instead of black?
Normal ListView
Scrolling ListView
Pressing ListView item
Use the attribute android:cacheColorHint="#000000" in ListView Tag
Regarding make TextView's color black or white, you can refer here to make a custom TextView for your ListView row, The extra work you have to do is just add another attribut inside TextView tag like this
android:textColor="#FFF" //or #FFFFFF for white
add a attribute on the ListView Tag
android:cacheColorHint="#00000000"// setting as a transparent color
This is due because of an optimization. To remove this, just set the cacheColorHint of your listView to transparent, like this: android:cacheColorHint="#00000000"
Full post here: http://android-developers.blogspot.fr/2009/01/why-is-my-list-black-android.html
You can Wrap that ListView inside on LinearLayout having same background and then remove ListView's Background that should work fine. :)
Please check this answer. I have got the same issue and it is fixed by putting view = null in adapter side.

How to get some space below my last list item alone- android

I have a list whose height is set to "fill parent". everything works fine but my last item in list touches the bottom of my screen. how can i get some space below my last list item.
You can add an empty view as footer: http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View)
AFAIK there's no way to do that only with XML, you can declare the footer in XML and inflate, or create programmatically
Here is a 3-liner to add a spacer programmatically:
View listFooter = new View(this);
listFooter.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.FILL_PARENT, 70)));
listView.addFooterView(listFooter);
uhmm.. seeing that you don't want padding, print a blank line (or transparent text) on a textview located after your listview. Or print a "extra" item on your listview.
you could use the Space widget
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="10dp"/>
can simply set the margin in the list ............
if need only bottom margin then use : android:layout_marginBottom=

Android - show footer divider but no list row divider

I have a list view which has a footer.
It displays numbers and at the bottom is the total.
I want to be able to show the rows without a divider between them. OTOH I DO want a divider before the summary row.
Is there any easy way to do this?
You can set android:dividerHeight to 0 in your list.
Then use custom layout for footer in which you add divider by yourself. For example, that can be a TextView with no text, android:layout_height set to 2 and android:background set to some color.
When you have custom layout for the footer, just add divider on top of it. It can be for example View of hight 2dp and different background color.
I had to do this programatically, since setting android:dividerHeight="0dip" in the XML didn't work for me:
getListView().setDividerHeight(0);

Categories

Resources