android-color

How to randomly receive a Material Design Color?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 06:34:46
问题 Google has their Color - Guidelines, so how to randomly receive a color? Is there a way to specify a number from the table and receive a random color out of all colors of the table? For example getMatColor(100); : EDIT - Result: (Icon colors) 回答1: Better late than never. My new response if the real purpose is to get a random material color for a type of color. Add the array.xml file (from @8m47x) <?xml version="1.0" encoding="utf-8"?> <resources> <array name="mdcolor_50"> <item name="red_50"

How can I get the primary color from my app theme?

。_饼干妹妹 提交于 2019-12-03 02:21:18
In my Android java code, how can I reference the color "colorPrimary" set in my theme? I have the following theme definition: <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <item name="colorPrimary">@color/myColor1</item> <item name="colorPrimaryDark">@color/myColor2</item> <item name="colorControlNormal">@color/myColor3</item> <item name="colorControlActivated">@color/myColor4</item> </style> I could reference the color resource directly (R.color.myColor1), but I would prefer to reference the theme's primaryColor setting, so that it stays consistent if the

How to give the user the possibility to switch between different colors skin in your App

余生颓废 提交于 2019-12-03 00:28:42
I want to give the user the opportunity to select wich color skin will have the app. For example, i whould implement a black skin with black colours with different tonalities and also a white skin with withe tonalities. Which whould be the best approach to achieve this? For example i know that there is a colors.xml file in Android that should contain the colours of your app. Whould be a way to have two colors files or something and to use one or other depending of user selection? Maybe a styles.xml file? Please tell me your opinion about which whould be the best approach to achieve this Thank

How to randomly receive a Material Design Color?

故事扮演 提交于 2019-12-02 20:13:06
Google has their Color - Guidelines , so how to randomly receive a color? Is there a way to specify a number from the table and receive a random color out of all colors of the table? For example getMatColor(100); : EDIT - Result: (Icon colors) Tibox Better late than never. My new response if the real purpose is to get a random material color for a type of color. Add the array.xml file (from @8m47x) <?xml version="1.0" encoding="utf-8"?> <resources> <array name="mdcolor_50"> <item name="red_50" type="color">#fde0dc</item> <item name="pink_50" type="color">#fce4ec</item> <item name="purple_50"

Change color of the drop down arrow of Spinner in XML

好久不见. 提交于 2019-12-02 15:24:38
As I wrote in my question, I want to change the color of the drop down arrow (the default arrow, not a custom arrow or something like that) of a Spinner in XML , but the problem is that I couldn't find anything to make reference to it from the XML . Is it possible? If yes, how can I change the color? Thanks in advance. There are three ways to achieve that. 1. Through code: In your xml, make sure your spinner has an id. Let's say we have a spinner with id "spinner". In your code, add the following in your onCreate(): Spinner spinner = (Spinner) findViewById(R.id.spinner); spinner.getBackground(

Defined custom shape for button in xml. Now I want to change the color dynamically. How?

做~自己de王妃 提交于 2019-11-28 13:07:07
I have this: round_button.xml <xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape android:shape="oval"> <solid android:color="#dec60000"/> <size android:width="150dp" android:height="150dp"/> </shape> </item> <item android:state_pressed="false"> <shape android:shape="oval"> <solid android:color="#860000"/> <size android:width="150dp" android:height="150dp"/> </shape> </item> My Button: <Button android:id="@+id/incrementBTN" android:layout_width="wrap_content" android:layout_height="wrap_content"

Defined custom shape for button in xml. Now I want to change the color dynamically. How?

自古美人都是妖i 提交于 2019-11-27 07:33:17
问题 I have this: round_button.xml <xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape android:shape="oval"> <solid android:color="#dec60000"/> <size android:width="150dp" android:height="150dp"/> </shape> </item> <item android:state_pressed="false"> <shape android:shape="oval"> <solid android:color="#860000"/> <size android:width="150dp" android:height="150dp"/> </shape> </item> My Button: <Button

How do I create ColorStateList programmatically?

半城伤御伤魂 提交于 2019-11-26 18:13:30
I am trying to create a ColorStateList programatically using this: ColorStateList stateList = new ColorStateList(states, colors); But I am not sure what are the two parameters. As per the documentation: public ColorStateList (int[][] states, int[] colors) Added in API level 1 Creates a ColorStateList that returns the specified mapping from states to colors. Can somebody please explain me how to create this? What is the meaning of two-dimensional array for states? See http://developer.android.com/reference/android/R.attr.html#state_above_anchor for a list of available states. If you want to set

getResources().getColor() is deprecated [duplicate]

筅森魡賤 提交于 2019-11-26 06:55:37
问题 This question already has answers here : getColor(int id) deprecated on Android 6.0 Marshmallow (API 23) (19 answers) Closed 3 years ago . Using: buildToolsVersion \"22.0.1\" , targetSdkVersion 22 in my gradle file. I found that the useful getResources().getColor(R.color.color_name) is deprecated. What should I use instead? 回答1: It looks like the best approach is to use: ContextCompat.getColor(context, R.color.color_name) eg: yourView.setBackgroundColor(ContextCompat.getColor

How do I create ColorStateList programmatically?

大城市里の小女人 提交于 2019-11-26 06:14:25
问题 I am trying to create a ColorStateList programatically using this: ColorStateList stateList = new ColorStateList(states, colors); But I am not sure what are the two parameters. As per the documentation: public ColorStateList (int[][] states, int[] colors) Added in API level 1 Creates a ColorStateList that returns the specified mapping from states to colors. Can somebody please explain me how to create this? What is the meaning of two-dimensional array for states? 回答1: See http://developer