I have a buttons and I want to make them look like a spinner.
I've found this post from 2011:
Android: Drawing a button as a spinner
And none of the solutions worked for me.
It's better if I could use my customed background.
Those are the buttons:
<Button
android:id="#+id/new_msn_act_type"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#drawable/button_border"
android:onClick="showPopup"
android:padding="6dp"
android:text="Order Type"
android:textColor="#color/colorPrimary" />
<Button
android:id="#+id/new_msn_datetimepick"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:background="#drawable/button_border"
android:onClick="pickDateTime"
android:padding="6dp"
android:text="Date and Time"
android:textColor="#color/colorPrimary" />
I tried each one of the solutions suggested in the post, including
style="?android:attr/spinnerStyle"
And they didn't work. How can I solve it ? Thanks
I need it to be a Button, because I want to use drawable style as background, and I want it to open PopupMenu and I worked hard for the popup to present icons correctly...
I solved it with:
android:drawableRight="#drawable/arrow_down_float"
You can also choose custom drawables
Related
I have found an answer to a question how to create heart shaped button using vector xml.
Answer is here:
https://stackoverflow.com/a/45618554/8523262
But I am not able to get it correctly implemented in my case.
I have two buttons side by side third would be this heart-Button. However, it does not fit correctly with other two buttons. I need it smaller than what original answer has it.
Here is my xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="7sp"
android:textSize="12sp"
>
<Button
android:id="#+id/buttonIA"
android:layout_width="0sp"
android:layout_weight=".3"
android:layout_height="25sp"
android:background="#drawable/buttondesign"
android:textColor="#color/white"
android:text="Hide Arabic Version"
/>
<Button
android:id="#+id/buttonIR"
android:layout_width="0sp"
android:layout_weight=".3"
android:layout_height="25sp"
android:background="#drawable/buttondesign"
android:textColor="#color/white"
android:layout_marginStart="7sp"
android:text="Hide Reference"
/>
<Button
android:id="#+id/buttonF"
android:layout_width="0sp"
android:layout_weight="0.3"
android:layout_height="25sp"
android:background="#drawable/buttondesign"
android:textColor="#color/white"
android:layout_marginStart="7sp"
android:text="Favorite it!"
/>
</LinearLayout>
Can anyone please tell me to resize it to look like a heart when placed inline with the two buttons I have already.
ButtonF is what I tried to set this vector as background of. Changed height/width too but didn't get it how i need it.
Thank you.
I use ImageButton Button instead of Button now. You could use ImageView too.
favoritebutton in below code is the vector xml that I shared link of in my questions, in case it helps anyone.
<ImageButton
android:id="#+id/buttonF"
android:layout_weight=".3"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/favoritebutton"
android:textColor="#color/white"
android:layout_marginStart="7dp"
android:background="#null"
/>
I'm using the support Toolbar and I've added some Buttons to it that I'd like to have mimic the ActionButton style. I got pretty close using style="#android:style/Widget.ActionButton", but the font size or style seems to be slightly off. Adding android:textStyle="bold" got me closer still.
<Button
style="#android:style/Widget.ActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST"
android:id="#+id/removeButton"
android:layout_gravity="center" />
I've also tried style="#android:style/Widget.Holo.ActionButton" and some others in the button which seems to change nothing
I'm not totally sure this is the right way, but I kept digging and this appears correct when adding android:textAppearance="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu" to my Button like so:
<Button
style="#android:style/Widget.ActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST"
android:textAppearance="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu"
android:id="#+id/removeButton"
android:layout_gravity="center" />
Hopefully it will help someone, as I couldn't find this anywhere. I apparently can't accept my own answer for a couple days.
I'm trying to make a list_item_view similar to
can anybody help me create it...
What i have tried
made separate view for the list items i.e list_item_even and 'list_item_odd'
for brevity i'll only show one of them, below is the code for list_item_even
<TextView
android:id="#+id/displaysms_lastmsgtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/displaysms_contactname"
android:layout_below="#+id/displaysms_contactname"
android:gravity="right"
android:text="88:88"
android:textColor="#10bcc9"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/displaysms_msgtext"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageButton1"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageButton1"
android:background="#fff"
android:shadowColor="#color/textShadow"
android:shadowDx="1"
android:shadowDy="1"
android:text="hi"
android:textColor="#color/textColor"
android:textSize="16sp" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/displaysms_lastmsgtime"
android:src="#android:drawable/btn_star" />
<TextView
android:id="#+id/displaysms_contactname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="45dp"
android:layout_toRightOf="#+id/displaysms_msgtext"
android:text="john"
android:textColor="#fff"
android:textSize="15sp"
android:textStyle="bold"
android:typeface="sans" />
and here is output
is it possible to create the yellow icon without using image and place an image inside it?
plaese help, Regards
is it possible to create the yellow icon without using image and place
an image inside it?
Maybe, but why put an unnecessary constraint on yourself? You can use a 9patch drawable for the yellow background thing if you're worried about stretching the pointed part. You can learn all about 9patch here.
i think you better off defining the layout programatically and check the row number if odd use one layout if even use a different one
if (row%2==0) use one layout
else use a different one
I am an entry level software developer, and have found tons of great answers from this site, but I can't seem to find how to hide the 'box' of a checkbox in Android. I just want the check mark to show, when a user selects an option. Here are some of the most recent things I have tried.
chkSortOrder.setBackgroundResource(android.R.color.transparent);
chkSortOrder.setBackgroundResource(android.R.drawable.checkbox_off_background);
Both of these still show the box.
put the following attribute in your checkbox tag in XML.
android:button="#android:color/transparent"
It's quite late but in any case, if it helps anyone. If you wanna set custom background to RadioButton programmatically, then you can set it like this,
checkbox.setButtonDrawable(null);
checkbox.setBackgroundResource(R.drawable.your_custom_drawable);
It's 2020! and many things have changed. But if you are struggling with this like me and tried everything here (and other solutions) with no luck, then try this one too. What I've got with other solutions came to this (Emulator, API 16):
Weird behavior! Two drawables, right is my custom box and default one on the left. And then accidentally i added this:
app:buttonCompat="#null"
and the second one is gone finally!
Here is the complete definition:
<CheckBox
android:id="#+id/cb_fs_ExactSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#null"
android:gravity="center_vertical"
android:padding="5dp"
android:text="#string/fs_options_exact"
android:textColor="#color/textPrimary"
android:textSize="#dimen/textSmall"
app:buttonCompat="#null"
app:drawableRightCompat="#drawable/drw_checkbox" />
You need to set both button and buttonCompat to null.
I found this error when updating from androidx.appcompat:appcompat:1.0.0 to 1.1.0.
None of the other answers were useful to me as setting button attribute to #null or #android:color/transparent doesn't work on Android API Level 20 or lower.
What I did is to change my CheckBox to ToggleButton and set textOn and textOff attributes to an empty string
<ToggleButton
...
android:background="#drawable/custom_selector"
android:textOff=""
android:textOn="" />
This way I could update to androidx appCompat 1.1.0
You can also toggle between a CheckBox and a TextView. Just make one view visible and another one hidden. This also makes sense because the CheckBox contains paddings around the check mark.
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<CheckBox
android:id="#+id/checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="#null"
android:checked="true"
android:gravity="center_vertical"
android:paddingStart="3dp"
android:paddingLeft="3dp"
android:text="My text"
android:textColor="#color/black"
android:textSize="12sp"
/>
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My text"
android:textColor="#color/black"
android:textSize="12sp"
/>
</FrameLayout>
I hate to be the third person to ask this, but the previous two askings haven't seemed to answer it fully. The android design guidelines detail borderless buttons, but not how to make them. In one of the previous answers, there was a sugestion to use:
style="#android:style/Widget.Holo.Button.Borderless"
This works well for a Holo theme, but I use a lot of Holo.Light as well and
style="#android:style/Widget.Holo.Light.Button.Borderless"
Does not seem to exist. Is there a way to apply a style for such borderless buttons in Holo.Light, or better yet, simply apply a borderless tag without specifying which theme it belongs in, so the app can pick the proper style at runtime?
Holo.ButtonBar seems to fit the bill for what I am looking for, except it provides no user feedback that it's been pressed.
Also, is there a place in the documentation that lists such styles that can be applied and a description of them? No matter how much I google, and search through the docs, I can't find anything. There is just a non-descriptive list if I right click and edit style.
Any help would be appreciated.
Edit: Got a perfect answer from javram, and I wanted to add some XML for anyone interested in adding the partial borders google has adopted.
Fora horizontal divider, this works great
<View
android:id="#+id/horizontal_divider_login"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#color/holo_blue" />
and this for a vertical one:
<View
android:id="#+id/vertical_divider"
android:layout_width="1dip"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#color/holo_blue" />
Simply add the following style attribute in your Button tag:
style="?android:attr/borderlessButtonStyle"
source: http://developer.android.com/guide/topics/ui/controls/button.html#Borderless
Check out my answer here. In a nutshell the correct solution is to use the following:
android:background="?android:attr/selectableItemBackground"
At the risk of beating a dead horse, here's another (possibly better) option. AppCompat v7 defines a borderless button style. If you're already making use of the AppCompat library, just go with that:
<Button android:text="#string/borderlessButtonText" style="#style/Widget.AppCompat.Button.Borderless" />
This code will remove all background for a button:
android:background="#android:color/transparent"
Just incase anybody is looking for light-weight solution to get the borderless button for the API's that do not support the Holo theme (like I did for a long time), Im posting my solution below:
<View
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="#505154"
android:layout_marginLeft="10dp" android:layout_marginRight="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn_Reply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#android:color/transparent"
android:paddingBottom="15dp" android:paddingTop="15dp"
android:textColor="#5c5966"
android:text="#string/btnReplyText"/>
<View
android:layout_height="fill_parent"
android:layout_width="1dp"
android:background="#505154"
android:layout_marginBottom="7dp" android:layout_marginTop="7dp"/>
<Button
android:id="#+id/btn_Delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:paddingBottom="15dp" android:paddingTop="15dp"
android:textColor="#5c5966"
android:background="#android:color/transparent"
android:text="#string/btnDeleteText" />
<View
android:layout_height="fill_parent"
android:layout_width="1dp"
android:background="#505154"
android:text="#string/btnReplyText"
android:layout_marginBottom="7dp" android:layout_marginTop="7dp" />
<Button
android:id="#+id/btn_Exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:text="#string/btnExitText"
android:paddingBottom="15dp" android:paddingTop="15dp"
android:textColor="#5c5966"
android:background="#android:color/transparent"/>
</LinearLayout>
All you have to do is change the colours and text to suit your own background. All the best!