I have started learning Android Studio and I am trying to change my button's background, but it is just not working.
Here is my code:
<Button
android:layout_width="300dp"
android:layout_height="200dp"
android:text="salam"
android:textSize="30sp"
android:textColor="#ffccee"
android:background="#ffffff"
/>
The background color stays the same after I change it.
So actually for some reason now Button only follows the colour which is in the theme of your activity but instead of going and messing with theme use AppCompatButton
<androidx.appcompat.widget.AppCompatButton
android:layout_width="300dp"
android:layout_height="200dp"
android:text="salam"
android:textSize="30sp"
android:textColor="#ffccee"
android:background="#ffffff">
</androidx.appcompat.widget.AppCompatButton>
Keep in mind even in future I would recommend using AppCompatButton.
Related
The background color in design view of android studio is not correct
This is my color.xml
The color of the button "=" is Orange and I do not set any color to the rest of buttons, but all button show purple in Design view
Did you change the theme? You can make your own theme (just a suggestion).
Or use AppCompatButton, example:
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/yourButton"
android:layout_width="200dp"
android:layout_height="45dp"
android:layout_marginTop="15dp"
android:background="#drawable/rounded_corners"
android:backgroundTint="#color/white"
android:contextClickable="false"
android:linksClickable="false"
android:text="Your text"
android:textStyle="bold"
android:textColor="#color/black"
app:layout_constraintCircleRadius="20dp"
app:rippleColor="#FFFFFF" />
I want to create the following without setting the style to legacy because it creates other problems for example for AutoCompleteTextView.
style="#style/Widget.Design.TextInputLayout"
You can use app:boxBackgroundColor="#android:color/transparent" on FilledBox style TextInputLayout to only have an underline without the box.
Like this :
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/outlinedTextField"
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:boxBackgroundColor="#android:color/transparent"
android:hint="label">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
And if you want to remove both box and underline use this : app:boxBackgroundMode="none"
As it's shown in the android studio it looks perfectly fine but whenever i run the app on my cell phone it looks like this any idea ,please ?? the app on the phone and the android studio
You are using Relative Layout.
First thing I noticed in your code is that you used margin buttom in Image view which is top of the screen already.So I suggest to not use Margin Buttom in that because relative layout bydefault keep that image on top .So i give you some idea to fix it.
1.)Image is on top so and its Relative layout.
<ImageView
android:id="#id/image" (give any id here)
android:src=""
android:marginleft="" ("Add ur dimensions")
android:marginright=""
android:adjustviewbound="True"/>
2.)Next is Textview.
<TextView
android:id="#id/text"
android:text="Name:Lovely Hamester"
android:layout_below="#+id/image"
android:margintop=""/>
So the main thing i wanna point of is this "Id".Relative Layout directly cant put views line by line like Linear Layout,We need to give command to the view to where it need to place.So thats why we use "layout_below" which instruct Text view to stay after imageview.There are different commands also.Please check that,like "layout_rightof","layout_leftof".
Just give id to every view and command them in Relative layout.Your other code is perfect.Dont use Margin Bottom , because it kept space from bottom which looks perfect in the preview but every Mobile have different size so thats why its not shows perfect in your screen.
just move code imageview to the top
example
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<ImageView
android:layout_width="200dp"
android:layout_height="600dp"
android:src="#drawable/test"/>
<ProgressBar
android:layout_width="48dp"
android:layout_height="48dp"
android:id="#+id/progressbar"
android:layout_centerInParent="true"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_notes"
android:layout_width="250dp"
android:layout_height="match_parent"
tools:listitem="#layout/item_note"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
android:src="#drawable/button"
app:borderWidth="1dp"
app:elevation="9dp"
android:backgroundTint="#FFFFFF"/>
</RelativeLayout>
The problem as i see it that you have a margin bottom override the layout align Parent Top so if you delete that and leave only :
android:layout_alignParentTop="true"
also it is redundant to call align right and left and bottom , align top will be enough.
i'm sure it will work.
I am working on an Android native app where I have a radio button group as given below side by side.
[radio btn] Option 1 [radio btn] Option 2
Now the problem is I'm supporting few languages and the radio btn labels are larger in some languages. Hence I want to ellipsize these labels so that they are always aligned on a single line. Any suggestions.
You can use android:ellipsize="end" and android:singleLine="true" properties as below,
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true" />
I'm not a designer but recently, I have been asked to change Login Screen UI for the app of my company.
I have got a background image from a designer. This image is a complete login screen. That means it is a single PNG file with the Input Box (User Name and Password Box) DRAWN on it.
Of course even it looks like a complete Login screen, just put it there won't work since the input boxes are fake.
I tried to put the EditText widgets on it, tried to let it just on the position on the background image and set these two widgets background to none so the user won't see it. However, on difference devices it just displays incorrectly. Sometimes above the "background input box", sometimes below it. Anyway, it just won't fit there.
I wonder if there is a way that could let me solve this problem. Let the widgets will be on that exactly position of the background, no matter how the devices changes.
Here is my layout now, and hope it will help:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainTableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/pbackground"
android:stretchColumns="1" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="160dp" >
<EditText
android:id="#+id/txtBxPassword"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:ems="10"
android:gravity="center_vertical|center_horizontal|center"
android:height="33dp"
android:password="true"
android:singleLine="true"
android:width="160dp" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/txtBxUserID"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_above="#+id/txtBxPassword"
android:layout_alignLeft="#+id/txtBxPassword"
android:layout_marginBottom="10dp"
android:ems="10"
android:gravity="center_vertical|center_horizontal|center"
android:height="33dp"
android:singleLine="true"
android:width="160dp" />
</RelativeLayout>
</RelativeLayout>
And here are the images I captured from Eclipse, as you can see I put two EditText boxes just at the position of the input boxes on background. But on the real devices, they will be misplaced.
Thank you!
put the linearlayout as base layout instead of relative layout...
and use tablerow layout and place the widgets in it
wisely use android:layout_margin and android:layout_width and android:layout_height
properly...
hope it would help
You should ask your designer to give you files for the individual elements -- e.g. the padlock & head icons on their own, and the shaded box on its own. Convert the box to a Nine-patch and set it as the background drawable of a suitable layout element (i.e. the container layout of each row).
You will also want to have multiple sizes of each image to support different pixel densities.
If you don't do this, you will always have some devices where the screen looks terrible.