custom button using android studio - android

when in my drawable layout (custom_button), codes are correct and the shape along with color pop on screen but when I use it in my activity layout (interface of my first page of app), the corners are good but the color I chose was not applied even though my code is correct.
this is my code:
<solid android:color="#00FFDD"/>
<corners android:radius="20sp"/>

If you are using a material theme, the button will have a tint that will change the button's background color.
You can simply remove the tint by adding this line to your button's xml code in your activity :
app:backgroundTint="#null"

Related

Background drawable not applying to Android button

I want to applying drawable to my android button.
But, background drawable is not working.
This is my drawable code.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFEF1D1D" />
</shape>
</item>
</layer-list>
and This is my layout code
<Button
android:id="#+id/booking"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6.5"
android:text="bokking"
android:textStyle="bold"
android:textColor="#color/white"
android:background="#drawable/booking_btn"
android:layout_marginRight="10dp"/>
Drawable is not applied to Button, but drawable is applied to AppCompatButton. I wonder why too.
When I applied this code, Only backgroundTint applies to buttons.
I spent a week on this issue, but I couldn't solve it.
plz help me
You can't apply the background on the material button.
If you are using Theme.MaterialComponents.*, then the normal button also used as the material button forcefully.
You have two options.
change it to any AppCompat theme.
Still If you need a material theme for some components, then use any material theme with a bridge. like Theme.MaterialComponents.*.Bridge
So, If you will go with option 2, you can use material button as per your need.
use com.google.android.material.button.MaterialButton for material button else use your normal button.
Looks like there is a problem with the Theme since Android Studio 4.1, try changing the base Theme from Theme.MaterialComponents.DayNight.DarkActionBar to Theme.AppCompat.DayNight.DarkActionBar, it works for me.
There is only one chance for that.I think you are using material theme.That's why the background property is not applying for button.If you want use that,change the theme to appcompat varaint.
You didn't use the selector in your XML. Use Selector instead of Layer-List

Android studio Button color not changing - Kotlin [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Here are my pics,
It is the code in which i have written the color code
Here is android blueprint here the color doesn't change
I have tried many ways like adding through styles too it didn't work out.
I have also tried to change background tint but it doesn't help either.
how can i change the button color?
i have shared my code in pics above.
Help me to change color
Just close the xml and reopen it. You will be able to find the defined color in your xml view. There is nothing to do with theme. Its just Android studio xml updation delay.
If it is not working then add below line to your Button tag
app:backgroundTint="your color code"
Add this to your drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#156667"/>
<corners android:radius="5dp"/>
</shape>
and apply it to your button's background in xml, you can change the color on <solid android:color="yourColor"/> there.
Since you are using a Theme.MaterialComponents.* theme the Button is replaced with a MaterialButton and by default has the backgroundTint based on the colorPrimary defined in your app theme
Use the backgroundTint attribute to change your color.
You shouldn't use the android:background attribute to change the color but if you want to use it to define a custom background you have to avoid that the button is tinted using:
<Button
app:backgroundTint="#null"/>
Also using the android:background attribute the MaterialButton doesn't use its own MaterialShapeDrawable for the background. This means that features like shape appearance, stroke and rounded corners are ignored.

How to change the colour of icon in android.

I have downloaded a check icon(24 dp) from android material design library from the link https://design.google.com/icons/. There are only two colours available black and white, but I need the colour of tick icon to be a shade of green(I have the colour hex code). How do I change the colour of icon in android and how do I change the shape as well. The shape that we get are square or circular. I need elliptical at one end and square at the other. Do I need to use some design tools for that. Thank you.
try with this excellent service
https://romannurik.github.io/AndroidAssetStudio/
make a selector for checked and unchecked icon like this
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="#drawable/checked" />
<item android:state_checked="false" android:drawable="#drawable/unchecked" />
</selector>
and apply it on checkbox using button attribute like this
android:button="#drawable/<your selector>"
You can use flaticon.com for checked and unchecked button
Download icon from https://icons8.com/. In this you can change color of icon as you want to do.
You can use the TintImageView within the appcompat support library and then tinting/coloring the imageview is by simply calling the android:backgroundTint to tint the imageview into one color.
add this line to your dependency:
compile 'com.android.support:appcompat-v24:+'
and then
<TintImageView
android:layout_width=""
android:layout_height=""
android:src=""
android:backgroundTint="#color/green"/>
so the above xml will tint the imageView to color green.
android:tint="#ffffff"
Add this attribute to the image view element.
1- Download font file from this page
2- Found the character entities for icons, using this page. For example alarm_on
3- Use like this example
4- Change android:textColor property from xml file

How to change widget background color without losing it's layout corners?

I am trying to change widget background color dynamically, but I lose the corners of my background layout (which uses colorless shape as a background), when I set background color.
In other words when I choose custom color for background and I apply it to the background it acts as I have applied a whole background drawable.
So how can this be done in other way, in order not to lose the layout corners, because without corners the widget looks bad.
The easiest way to do this is to add ImageView as a background, to your primary layout (fill_parent), and set its background to #drawable/background_with_corners which has the following code:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="3dp" />
</shape>
And then from your code callremoteViews.setInt(R.id.backgroundimage, "setColorFilter", color); to apply the selected color to the image retaining the shape.
And if your color has transparency call remoteViews.setInt(R.id.backgroundimage, "setImageAlpha", Color.alpha(color); if SDK>=16; else remoteViews.setInt(R.id.backgroundimage, "setAlpha", Color.alpha(color);
I hope this helps.

Android view state_pressed Blue background

I have a lot of custom views and I have style for state_pressed. Basically its a rectangle with
solid android:color="#DC2D5A8C"
What I am trying to do is simulate the blue background color that comes with the standard views/controls. For example: when you click on a button or list view item, the background changes to blue (on_pressed).
I got that to work with the above style, but the problem is let's call it the tint effect. In a button, the text caption is black. When you press, the background is blue and the text color changes to white.
Now how can I achieve such a so called "tint" change in my custom control's view?
Your response is much appreciated.
Thanks!
You can use selector xml file to do this.You must be setting background to the button.Instead of that set the xml file to its background.Create selector.xml file in your drawable folder as shown below and set that xml file as background to that button just like : android:background="#drawable/selector"
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use blue -->
<item android:drawable="#drawable/btn_blue"
android:state_pressed="true" />
<!-- When not selected, use black-->
<item android:drawable="#drawable/btn_black"/>
</selector>
By doing this you will get so called tint effect to your button.Hope this will help you.

Categories

Resources