I have a widget with a button, an image and a title and a black background (linear layout). These views are separately clickable. But how to treat all as a single item? (like androids default power widget has an icon and a green bar at bottom but acts as a whole and an orange border is shown on press). i need on click whole widget area is lit and again on click whole widget area is greyed. e.g an invisible button covering the whole widget area is also ok. thanks for your help in advance.
For the child views you need: android:clickable="false" and android:duplicateParentState="true". This causes the child views to not be clickable and to also take on the parent view's state (e.g., pressed). For the parent view you need to set android:clickable="true". To make it clickable. Then you only handle the onClick event from the parent view.
Views, just like buttons, have the setOnClickListener() method. By setting android:clickable="true" in the XML, you can handle the onClick the same as you would handle it for any other object.
Related
I have a menu with checkable items. I want to put the CheckBox first and the Text to the right of the CheckBox. Any idea how to do this?
It's not possible to do this using menu items. What you can do, is use a custom Toolbar with a custom ImageView(aligned right) with the image src as the overflow icon (the one with 3 vertical dots). Also create a custom view(let's say checkBoxList) in your layout, which contains the text to the right of checkbox, the way you want it. Keep this checkBoxList aligned to the top right of your parent layout (super easy if you are using ConstraintLayout). Also, keep the visibility of this List to invisible. When overflow icon get's clicked, set the visibility of checkBoxList to visible. Also, have an onClickListener on the parent Layout, where you set the visibility of checkBoxList back to invisible( So that when the user clicks on anywhere outside checkBoxList, it closes).
I want to attach an onClickListener to an ImageView which is made INVISIBLE. I know I could set it to the TRANSPARENT color but due to certain reasons I don't want to do that and an INVISIBLE ImageView is not listening to clicks. Is there any way to achieve the required thing?
No, INVISIBLE views don't receive touch events. However there are a few alternatives you can use:
Set the view's alpha to 0. This would make it fully transparent.
Create a 2nd view of the exact same size above the view and put the click handler on that.
Put a touch handler on the parent and check if in the area of the invisible view when you detect a click.
Least work is probably top to bottom on that list.
I need to add a Button that is attached to the bottom of the screen so that it remain in that place when scrolling (other widgets move, but this don't). How to do it?
Put everything that you want to scroll in scrollview.
You want that button at the bottom of the layout. Set android:layout_alignParentBottom="true" in the xml of the button.
I'm implementing the UI like the picture below. I'm using gridview to this layout. When user tap the item in gird. It show a circle overlap to the other item. I don't how to do it. at first I define a layout with the circle is gone and add onclicklistener. If user tap on that, I visible the circle, but the size of gridview also extend. Can you help me provide solution?
You can add this views in gridview parent layout preferable relative layout. You must add them after your grid view initsialisaton is done and onitemclick listener on grid item to make them visible. Exactly the one you've tryed but not in grid view but in the activity rootlayour.
I've got listview that in a row it contain 3elements: imageview, textvie and another imageview. I've set my listview to setItemsCanFocus(true) and every item is set setFocusable(false). Screen:
http://img252.imageshack.us/img252/4042/zrzutekranue.png
I can navigate on the screen (click on text/image, I have those fields set to clickable and focusable), but there is no visible focus. I'd like to have the default focus style, when background changes.
I can add sth like:
setBackgroundColor(xxx)
but I'd like to have that fancy background that is lighter in the middle and darker at the ends.
The upper row on the pic is what I've got, and lower is the ideal focus notification, of course it should be narrow so it would only be background of the text view.
Sorry for my English.
PS I also used for textview
android:layout_height="fill_parent"
to fill for height which isn't the best piece of coding.
In the List View, all the list items are in different views. In your case the Image View, Text View And Image View lies within a single View. So according to me you cannot have focus on the items within a single View in a list View.