When I place a button in a layout, it has a standard gray background. However I want to make it more like the kind of button you see in the Dialogs where it's a background-less button (e.g. the white buttons with text).
Like this
Not like this... not like this...
Old question but I just stumbled on it and have the answer (or at least I think), I really don't know if that's the best approach, but it should do the job.
<Button
android:id="#+id/sign_in_button"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
The trick here is the #style/Widget.AppCompat.Button.Borderless.Colored. Also see this answer, it explains a lot https://stackoverflow.com/a/36666660/1920068
try this
android:background="#android:color/transparent"
Just use a TextView instead, and put a click effect with the background:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#23ac29"
android:text="Signup"
android:textSize="18sp"
android:padding="8dp"
android:background="?android:attr/selectableItemBackground"/>
Related
I'm wondering how can I create something like this photo, I can do it by creating two of TextView but is there any easier way, or is there an external library?
You can use Android Textview attributes just like shadowDy shadowDx and shadowRadius.I hope it might be helpful for you.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="#string/shadow"
android:textSize="80sp"
android:textStyle="bold"
android:shadowColor="#7000"
android:shadowDx="12"
android:shadowDy="12"
android:shadowRadius="8"/>
and You can also check it from this link there are some slides related to textview styles https://chiuki.github.io/advanced-android-textview/#/8
So, the title may be confusing, but to put it in context:
I have an ImageButton component in my app display that should be on the opposite side of my ImageView, lined up perfectly, and to repeat this for any other item on the same list.
My question and doubt itself is how to do this when the ImageButton in this case is inside a LinearLayout while the ImageView is outside of it. Is there like a code line that can connect an outside element to a LinearLayout inside element.
Here's how my display looks:
item_contact.xml
The blue rectangle, being the LinearLayout, means everything inside belongs to it, but the call button looks to be the on the other side of the user pic, which is not inside the LinearLayout, which is what I wanted, the problem is this:
activity_main.xml
Each of the TextViews are above and below both the user picture and the call button, but because they both also belong to the LinearLayout, it's obvious it's because of the latter.
Now I tried fixing the problem by simply adding the user picture to the LinearLayout, which seems like the obvious answer, but I needed to be sure, because my call button isn't correctly aligned to the right:
<ImageView
android:id="#+id/iv_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/todo"
android:src="#drawable/ic_baseline_person_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="ImageContrastCheck" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#id/iv_image"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<TextView
android:id="#+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:textColor="#color/purple_700"
android:textSize="18sp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/call_button"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginStart="248dp"
android:background="#1072E1"
android:contentDescription="#string/call"
android:minWidth="48dp"
android:src="#android:drawable/stat_sys_phone_call" />
<TextView
android:id="#+id/tv_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="14sp" />
</LinearLayout>
My ImageButton's "right alignment" was only done with the manual positioning of the android:layout_marginStart which I set to 248dp by attempts. Surely there's a better way to do this, but I've yet to find a solution that works.
Lastly, there's also the aforementioned problem: I can't seem to fix the LinearLayout issue without having to backtrack the progress I've done and use new code lines or already existing ones to resolve the issue.
So:
How can I "connect" two components, one inside a LinearLayout and another not, with or without the use of constraints and/or RelativeLayouts, and do I really have to insert the outside component to the LinearLayout;
How can I forcefully align a component to the right without having to manually push it with margin inputs (attempts);
Is there a way to know exactly how to connect a component to another by using constraints accurately, so it repeats that process through the entire contact list?.
I would really like if someone could answer at least one of the listed questions or, even better, resolve one of the most developed questions, where I show some images of reference.
Maybe even a suited tutorial for my case in specific that explains the ways of designing the layout of an app.
If more information is needed, I will gladly help, and I'll also try to answer to every response I can get.
Also, in case you're curious, here's my last question about the same app (already resolved):
"[AppName] stopped working" when I try to run my app on an AVD emulator
(Keep in mind that the problem at hand in this question has barely anything to do with this one.)
I am trying to set drawable in my button but its not showing properly. Here is what I want to achieve
but I am unable to get the required results.
This is what I am doing
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btnShareStore"
style="#style/yellowButton"
android:layout_marginTop="#dimen/margin_large"
android:layout_marginBottom="#dimen/margin_small"
android:layout_weight="1"
android:drawableStart="#drawable/ic_vector_share"
android:text="#string/lbl_share_store"
android:layout_marginStart="#dimen/margin_large"
android:layout_marginEnd="#dimen/margin_small"/>
and this is how it looks like
How can I move drawable to the adjacent left side of text?
Any help will be highly appreciated
You can try with this, keep in mind that it will need your app theme to be a descendant of MaterialTheme.
<com.google.android.material.button.MaterialButton
app:icon="#drawable/icon_search"
android:text="Hello"
app:iconGravity="textStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
This is my XML for my check box:
<CheckBox
android:id="#+id/atm_checkbox"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/input_color" />
And it looks like this:
http://imageshack.us/photo/my-images/528/47342915.png/
This is what i found on internet:
<CheckBox
android:id="#+id/chkAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/chk_android"
android:checked="true" />
which looks like this
how to change my checkbox to look like the one i found on internet.
As my rep is <10 i cant upload image of my checkbox, or can anyone help me how to style checkbox to make it look better
I think both the xmls have similar code, but why are they looking so different?
If you want custom the look of checkbox see this tutorial and find everything.
By the way, the checkbox from your link is for Android3.0 and above.
CheckBox derive from Button class, so you can set a background image like button. See this link, may be it is what you are looking for.
If you want a clean design without codes, use:
<CheckBox
android:id="#+id/checkBox1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:drawableLeft="#android:color/transparent"
android:drawablePadding="10dp"
android:text="CheckBox"/>
The trick is to set colour to transparent for android:drawableLeft and assign a value for android:drawablePadding. Also, transparency allows you to use this technique on any background colour without the side effect - like colour mismatch.
When im designing my android app im using XML and for this app im using the Relative layout but when i put the buttons on my screen with the png background i made its just looking bad.. the buttons are not put equaly like they should..
Look at this picture:
How would i solve so the pluss buttons and percent and comma and equal button will be placed right instead of looking all that weird?
If you are intrested to see my XML code here is an link for pastebin:
http://pastebin.com/gpxnPT4P
I think you have to check the android:layout_... of every item that is showing wrong. For example, the declaration for the number 5 button is:
<Button android:background="#drawable/number5" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:id="#+id/number5" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="#+id/number8" android:layout_alignLeft="#+id/divided"></Button>
If you look closely the android:layout_alignLeft declaration is pointing to de divide button (#+id/divided) that is far away. There is a similar situation with the button for number 6.
Try this declaration for number 5 button:
<Button android:background="#drawable/number5" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:id="#+id/number5" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="#+id/number8" android:layout_alignLeft="#+id/number4"></Button>
Hope this helps