How to change background color android studio

How to change background color android studio

Set Background color programmatically [duplicate]

I try to set background color programmatically but when I set every one of my colors, the background being black but with any color background being white like the application theme.

Can you see the code?

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

8 Answers 8

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

you need to use getResources() method, try to use following code

Edit::

getResources.getColor() is deprecated so, use like below

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

The previous answers are now deprecated, you need to use ContextCompat.getColor to retrieve the color properly:

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

Otherwise you can do as others have suggested with

I don’t recommend using a hex color directly. You should keep all of your custom colors in colors.xml.

you must use getResources().getColor(R.color.WHITE) to get the color resource, which you must add in the colors.xml resource file

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

If you save color code in the colors.xml which is under the values folder,then you should call the following:

name means you declare in the tag.

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

In my case it wasn’t changing the color because I was setting the color in my xml resource.

After delete the line that set the color it worked perfectly programmatically

Android Studio, change the editor background color (not the whole theme)

The same question was marked as «duplicate» even though it obviously was not a duplicate. At least it should be obvious to anyone who is familiar with configuring an editor. When you want to change the background color, you aren’t talking about changing the whole theme, you are talking about changing the background color.

Is there a way to change only the background color in Android Studio editor?

7 Answers 7

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

Sorry, but I believe you all have this one wrong. To change the background of the editor goto File, Settings, Editor, Colors & Fonts and select General. You’ll see an item called «Default text«. On the right of the window you will see a checkbox for background. Click in the color window and choose whichever color you prefer. Now the entire editor window will show that color as the background.

go to : Android Studio > Preferences > Editor > Colors & Fonts > General

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

Yes it is. Open Settings (Preferences on a Mac) and under IDE Settings expand Editor, Colors & Fonts and select General. You’ll see Background in a menu on the left side. Click on the checkbox next to it if it’s not ticked already and then double click on the square filled with current background color to get the color picker.

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

Android Studio 4.1.2 on Mac

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

None of the Answers above have correct info for Windows Android Studio 3.1.2.

On Mac, apparently this works: go to Android Studio > Preferences > Editor > Colors & Fonts > General, but we Windows folk don’t have an Android Studio tab or option and Preferences isn’t an option anywhere.

We have File > Settings > Editor. Here’s the screen with the only conceivable next links to click highlighted:

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

But here’s what I see when I click General. I can select this background:

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

But I can’t live with that.

In Windows 7, AS 3.1.2 the menu sequence—File > Settings > Editor > Color scheme > General > Text > Default text—takes you to a screen where you can set the foreground and background colors via a «color circle» or by typing in your favorite RRGGBB code(s).

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

I was pleasantly surprised by how an error in an xml file showed up (and the current line):

How to set background color of a View

I’m trying to set the background color of a View (in this case a Button).

I use this code:

It causes the Button to disappear from the screen. What am I doing wrong, and what is the correct way to change the background color on any View?

21 Answers 21

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

You made your button transparent. The first byte is the alpha.

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

When you call setBackgoundColor it overwrites/removes any existing background resource, including any borders, corners, padding, etc. What you want to do is change the color of the existing background resource.

Experiment with PorterDuff.Mode.* for different effects.

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

Several choices to do this.

Set background to green:

Set background to green with Alpha:

Set background to green with Color.GREEN constant:

Set background to green defining in Colors.xml

or the longer winded:

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

You can set the hex-color to any resource with:

The code does not set the button to green. Instead, it makes the button totally invisible.

Explanation: the hex value of the color is wrong. With an Alpha value of zero, the color will be invisible.

The correct hex value is 0xFF00FF00 for full opacity green. Any Alpha value between 00 and FF would cause transparency.

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

For setting the first color to be seen on screen, you can also do it in the relevant layout.xml (better design) by adding this property to the relevant View:

and what is the correct way to change the background color on any View?

Change App Background Colour in the Android Studio

In this tutorial, we will take about how you can change app background colour in the android studio using the Radio Button inside Radio Group.

Developing boring Apps and publishing them just the sake for it won’t help you to gain many downloads for your App and maybe you would end up having bad ratings for your App on the Google Play Store.

Change App background colour in the Android Studio

How to change background color android studio. Смотреть фото How to change background color android studio. Смотреть картинку How to change background color android studio. Картинка про How to change background color android studio. Фото How to change background color android studio

Change App Background color in the Android Studio

I would give you full code below at the end of the post including XML file along with the main Java file.

In this tutorial, we would put three radio buttons with each labelled with different colour names. Once a user clicks on a particular Radio button. The background of the App would change according to the colour mentioned beside the radio button.

Activity_main.xml

As stated above in the post that we are going to put three radio buttons, I have included three RadioButton tags each one having its text color set to different ones.

You have to put RadioButton inside the RadioGroup Tags.

Also, note that we have given android:id within the tag of RadioButton, as well as layout_width and layout_height, is also set to wrap_content.

How To Change App Background Colour Using Java

As you can see from the code I have mentioned color codes in Hexa format

In order to change the color of the background once the radio button is activated, we have used onCheckedChanged function and setOnCheckedChangeListener on radioGroup.

MainActivity.Java

How To Change App Background Colour Using Kotlin

MainActivity.kt

ScreenShot

Result

Thus you can see that upon clicking on different radio buttons the background colour is changing accordingly. This would make your App look attractive if you are a beginner in Android Development. Do try these on your own.

Thanks a lot guys for following our series on Android Tutorials. If you want a tutorial on any topic do let us know in the comments section below. We would try to upload it here on AndroidHire.

How to Change the Background Color of Button in Android using ColorStateList?

ColorStateList is an object which can define in an XML file that can be used to apply different colors on widgets (such as Buttons, etc) depending on the state of Widgets to which it is being applied. For Example, There are many states of Buttons like (pressed, focussed, or none of them ) and other widgets states like enable, checkable, checked, etc, Using Color State List is a nice way to change the color of the button without using shape drawables or custom images. One should remember the color state list can be used anywhere, where color is used. The color state list is defined in XML and saved under the res/color folder. The root element of the color state list is a selector and the item element is defined for each state that you want to define the color by using color and alpha attributes. The default color should be the last element which is used when color for a specific state is not defined. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Kotlin language.

Approach

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *