I've been searching for this for quite a while but can't seem to find it.
Is there any predefined widget in Android to implement a basic clickable item (with one of two lines of text) whose background turns to the theme's color when clicked, like the ones seen here, for example:
And I mean, without using the PreferenceActivity class, which implements this automatically. Does this exist or do I have to implement my own customized view?
Thanks!
Edit:
I've added a TwoLineListItem like this and it doesn't react to clicks (background doesn't change)
<TwoLineListItem
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
>
<TextView android:id="#android:id/text1"
android:layout_marginTop="1dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:text="Meh" />
<TextView android:id="#android:id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#android:id/text1"
android:layout_alignLeft="#android:id/text1"
android:paddingBottom="4dip"
android:includeFontPadding="false"
android:textSize="15sp"
android:textStyle="normal"
android:text="Moo" />
</TwoLineListItem>
Does it only work inside ListViews? Because that way I'll have to define my buttons in code and not in the XML, right?
Thanks!
The default layout for that is called android.R.two_line_list_item given by android.
All the items in a ListView support this transition.
Best wishes,
Tim
Related
Please click here to see the screenThis is a screen of a blood bank, I am developing but I am stuck at implementing the choose blood group option. Should I use them as buttons or text views? Also I want only one option to be selected, since a person cant have more than 1 type of blood group. Also the option selected must move on to the next activity.
There's two way to do it.
Chip Group
Radio Button.
Here I am implementing source code of Chip group.
<com.google.android.material.chip.ChipGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.chip.Chip
android:id="#+id/chip4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text"/>
</com.google.android.material.chip.ChipGroup>
You have to add more chip. Only single chip can be selected at once. If you want to enable multiple chip. Than, you have to remove ChipGroup or, create more ChipGroup.To do like that picture you have to change colors.
RadioGroup :
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RadioButton
android:id="#+id/radioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
Radio Button works like that but, radioButton design isn't like as you shown.
Use MaterialButtonToogleGroup from Material Components. Inside it use MaterialButton for choices. For more information please refer to this link
Currently I'm trying to insert a drop-down kind of sliding menu (not sure how it's called). The idea is that user touches the arrow or any area of the menu and drag upwards in order to open the menu. But I have no idea how or where can I find tutorial for this.
Check this code posted in github: https://github.com/umano/AndroidSlidingUpPanel.
You can design your own view in sliding menu.
<com.sothree.slidinguppaneldemo.SlidingUpPanelLayout
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="My Content"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:text="Another Content"
android:textSize="16sp" />
</com.sothree.slidinguppaneldemo.SlidingUpPanelLayout>
The easiest way would be using a library like https://github.com/umano/AndroidSlidingUpPanel
But since google released CoordinatorLayout and Behavior I would recommend you to take a look at that, although it's kinda new and much harder to do.
As a beginner in Android, I'm trying to display a tree. I have already found how to add programmatically new TextViews but I don't know how to place them, I mean how to set their padding/margin depending on the father node.
Thanks a lot for your answers,
Baptiste
Dear first Use relative layout as parent and then add text view child.i did not add relative layout add relative layout as parent.
<TextView
android:id="#+id/txttxt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="node"
android:textColor="#color/white"
android:layout_alignParentLeft="true"/>
<TextView
android:id="#+id/txttxt12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_below="#+id/txttxt1"
android:text="Child"
android:textColor="#color/white"
android:layout_alignLeft="#id/txttxt1"/>
this is sample code i made for you. you can use according to your requirement.
I have multiple ImageViews which are transparent and are meant to over lap one another. I am aligning then to one another but one problem presist. How can I set the order in which they are layered? Ive tried revising the code in both xml and how the images are set in the actual java code...
I have tried FrameLayout but maybe Im not using it right...here is my implementation:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".RadarActivity" >
<ImageView
android:id="#+id/imageview_topo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:scaleType="center"
android:visibility="invisible" />
<ImageView
android:id="#+id/imageview_counties"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:scaleType="center"
android:visibility="invisible" />
No matter what I do...imageview_topo is always placed on top. Even in the code i have instantated topo first and retrieved its image first!
Thank you!
I referred a site here that says:
If multiple child views exist, then they are drawn, in order, one atop
the other. This means that the first view added to the frame layout
will display on the bottom of the stack, and the last view added will
display on top.
You can check this site too: http://blog.neteril.org/blog/2013/10/10/framelayout-your-best-ui-friend/
May be i can help you more if you show the screenshot of your UI.
I am trying to figure out how to make my layout have the following coded buttons stay in their place despite future dynamic activity, maybe through reserving a free space. In between the menu button and the other three buttons will be a grid of buttons with both random size and in random amounts based on preselections created dynamically. But no matter how many buttons or the sizes I want these four buttons designed in main.xml to remain in their proper positions.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="MENU" />
This is the area of concern. I want to make it where the menu button (above) is always attached to the top of the screen and the step, pause, and simulate buttons (below) are always at the very bottom of the screen.
<Button
android:id="#+id/step"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/grid"
android:layout_centerHorizontal="true"
android:text="STEP" />
<Button
android:id="#+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/grid"
android:layout_toLeftOf="#id/step"
android:text="PAUSE" />
<Button
android:id="#+id/sim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/grid"
android:layout_toRightOf="#id/step"
android:text="SIMULATE" />
<SeekBar
android:id="#+id/speed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/sim"
android:layout_alignParentLeft="true"/>
</RelativeLayout>
I just figured out a solution my own question.
I had to use "android:layout_alignParentBottom="true" after the menu button on the other three buttons, now any buttons added dynamically can be placed in between as needed.
The website wont let me answer my own question.
Make your RelativeLayout a LinearLayout. Give all Buttons "android:layout_weight="0"". Then at the desired empty space, add a View that has android:layout_height="0" and "android:layout_weight="1"". That should do it, provided I understand your question correctly.