In the native Gallery app on Android, when Select item via Option Menu action, you can select multiple items, each grid item which will have a colored-border overlay on top signify as selected when clicked.
Question:
How to do this dynamically using getView() in the ImageAdapter
class? (since there is setBackgroundColor() but not setBorder()
Is there a better way to accomplish this? (such as creating a padding
of some sort for the image within the gridview cell, then set the
background color which will look like a border)
I finally decided to use the 2nd method in the original post: creating a padding for ImageView within the gridview cell and set the background color.
I used ImageView.ScaleType.CENTER_CROP with setCropToPadding(true); for the ImageView.
Related
I am unable to get the first button in a gridView to change colour. The button works fine, and it operates as normal when it is clickd but it wont update the colour of the first button. I am using a custom list adapter to generate the gridView. This only seems to happen if I want to change it in real time, if i load the buttons at a later stage the buttons do change colour. I've tried to hard code it for the first button in the list but that doesn't seem to work either.
In Grid view First you have to create a custom adapter for it and then in the Override method "get View()" you will get the specific cell and then change its background color.
For Details click the link : https://developer.android.com/guide/topics/ui/layout/gridview.html
I'm working on a GridView with setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL). By default, rows are not getting highlighted (with the blue highlight you see on WhatsApp or Gallery apps), so I am wondering, does the Android API already takes care of highlighting the selected items and I am missing something (if so, what am I missing?) or do I have to take care of highlighting selected rows by myself (if so, how to highlight, not just change the background)?
Here's my code:
gridView.setOnItemClickListener(this);
gridView.setEmptyView(view.findViewById(R.id.empty));
gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
// multiChoiceModeListener is a subclass of AbsListView.MultiChoiceModeListener
// with no particular code on its abstracts methods.
gridView.setMultiChoiceModeListener(multiChoiceModeListener);
Use this for your ListItem background (XML layout)
android:background="?android:attr/activatedBackgroundIndicator"
It's basically only a selector, you can also build yourself: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/drawable/activated_background.xml
EDIT:
Given your comment, this solves it:
android:foreground="?android:attr/activatedBackgroundIndicator" with a FrameLayout
Also related question: How to set foreground attribute to other non FrameLayout view
I have a doubt I have a listview and below it there is a background with a image. I would like to have the lists with a transparent color in order to see the image in the background with the ListViews color. I have tried using a selector but it just applies to the select item i the listview.
Maybe it is not very clear so for that purpose I attach the following picture where the listview and the background is shown:
As you can see the item background is with color but the image is still visible
Thank you very much
Add following property in ListView...
android:cacheColorHint="#00000000"
it is for transparent background of ListView.
More detail see Here.
You can also use an image editor to edit the opacity of the image/shape/gradient/whatever that you're using for the rows. I use Gimp because it's free. Here's what you need to do in Gimp: Go to the 'Layers - Brushes' window. Right-click the image layer and 'Add Alpha Channel'. Then just dial down the Opacity using the number picker (located above the layer) and File -> Export the image. Add this image to your project. Set it as the background for the List View rows. Then set the background for the List View itself to whatever you want to take up the entire background behind the List View.
I managed to achieve this with the RecyclerView by adding this line of code to the 'onBindViewHolder' method in the 'RecyclerView.Adapter' class:
((RelativeLayout) holder.itemView).getChildAt(0).setBackgroundColor(Color.parseColor("#00FFFFFF"));
Bear in mind that the view returned by the above cast expression is an 'android.support.v7.widget.CardView' that contains the list item layout
I want to create a gallery view, in which I want to select multiple images using an orange rectangular box.
It should look something like the following:
screen look like http://i.imgur.com/qAO0Q.jpg
Issues in your design:
Doing the selection by dragging the thumbs on either sides is going to be an extra headache. First of all, handling scrolling while doing selection. Secondly, handling touch/drag and deciding whether to include an item in the selection or not.
Design change:
Let me suggest a simpler way to extend your selection rectangle :
I assume the selection starts with a long click on any item. The orange selection rectangle appears over this initial item. Then a single tap on any neighboring item should include all items placed in-between the tapped and the initial item including the tapped one. That will make selection handling significantly simpler and less buggy.
Implementation:
Now this design shouldn't be too difficult to implement. Extend the Gallery widget and have members that indicate whether a selection is in progress and what is the range of selection (startIndex and endIndex) .
Override the onDraw method and draw the selection rectangle from startIndex to endIndex items.
Then you can define a custom adapter for your GalleryView, define a row XML layout file with ImageView and CheckBox and inflate this XML layout inside the custom adapter class. FYI, you will define custom adapter class by extending BaseAdapter class.
Check this example: Android custom image gallery with checkbox in grid to select multiple
What you could do:
Give ids all the images in the slide show
Use javascript to set
onclick events for the images Enable borders on the onclick event
Add to img tags
<IMG id=”1” namespace=”clicked” onclick="TriggerEvent(this)"></IMG>
Create script trigger event that changes the namespace of the selected id.
Include css to enable the borders:
.clicked{
border-style:solid;
border-width:3px;}
I have written code for a custom ListView. It is just a view with three textfields. I have used setBackgroundColor to set the row background to white. However, when I click on a row, the color no longer changes. I am doing this entirely programmatically. Is there a method to get back the Android selector color on clicking a ListView row?
The changing selection colour is a property of the background drawable belonging to the list item. You will have to specify one yourself, using a state list drawable.
More info here:
Drawable Resources: State List
And here:
What is the default drawable for pressing a list item
Annoyingly, the system's default list item background is not accessible from apps, so you'll have to copy the original (or use your own style if you prefer).