what style/attr/drawable for inverse background? - android

I try to make a ExpandableListView where the group headers are drawn inverse. There is no problem with changing the text color, size etc. via XML. I even found out how to use the system defaults like
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="#android:style/TextAppearance.Medium.Inverse"
/>
But for the background color?! I don't understand why these styles don't include background color information?!
Of course I could use a direct color, but I look for good default background attributes or styles. Like "style/Background.For.TextAppearance.Medium.Inverse" ;-)
What would be a good solution? So that for the dark themed devices I get white/gray, and for the white themed I get black?
Or should I simply use R.color.background_light?
Greetings, Joerg
PS: First question here ;-) Thanx to all the people answering here the last months and years: You great people made it much more easier for me to find a re-entrance in programming after 12 years break ;-)

As you observe, the styles with "TextAppearance" in their name only affect the foreground text attributes of the view. They are appropriate for the android:textAppearance attribute. The styles with "Widget" in their names define all the UI properties and will work in a style attribute, but Android doesn't define a "Widget.TextView.Inverse" style.
When I wanted to display an console-like log as an inverse text view, I used the following XML:
<TextView
android:textAppearance="#style/TextAppearance.AppCompat.Small.Inverse"
android:background="?android:colorForeground"
... />
It uses the theme's foreground color as the background for the view. With a dark theme it displays dark text on white, and in a light theme it displays light text on black.

Related

Where can I find defined colors in android

I've created the project from default template Bottom Navigation Activity. I found that the background color for BottomNavigationView is #2D2D2D for dark theme. I defined it in colors.xml, but I'm not sure that it's good solution. Is there any pre-defined colors in system(smth like #android:color/theColorThatINeed)? Where can I see all of them?
the best practice is to use colors.xml, and put there all of your colors,
and then call it like this:
android:background="#color/red"
there are also system constants for colors, which contains this constants:
http://developer.android.com/reference/android/R.color.html
this resources are read only and you can not add to them more constants.
Unfortunately there isn't a single place to find all the 'system colours'. You can either find them through documentation, which is usually easy with the material components (which is where BottomNavigationView is from), or by trawling through the source code. For your particular example the colour you're after is ?attr/colorSurface, which is in the documentation and the source code.
Is there any pre-defined colors in system?
Yes, there is but it's limited. These colors are defined in android.R.color. Here are some of them.
background_dark
background_light
black
darker_gray
holo_blue_bright
holo_blue_dark
holo_blue_light
holo_green_dark
holo_green_light
holo_orange_dark
holo_orange_light
holo_purple
holo_red_dark
holo_red_light
transparent
white
widget_edittext_dark
To use them:
android:background="#android:color/background_dark"/>

What is the Material design grey color of icons in Android?

I'm looking for the default Material design grey color of icons in Android. I use two icons but for some reason one is black and one is grey (although they original should be both black) and they have the exact same code:
I want to set the default grey color. Where can I find it? Even the hex value should solve this problem.
Using an eyedropper tool I found the hex code for the grey envelope, it's #737373.
If you're doing design work installing a tool like Color helps when it comes to finding an element's hex color. It includes an eyedropper tool that lets you click an element and get it's hex color.
For changing icon color try:
<ImageButton
android:layout_width="your value"
android:layout_height="your value"
...
android:tint="YourColor"
/>

Change Android EditText background color

I am developing an Android app. There's this issue with the EditTexts, because in some devices the "background" is white (which is the way I want it), but on others is transparent, and makes the app less professional. Here's an image with the "white background":
On other devices the edit texts that say "Yo" and "Casa" are transparent, so the words mix with the map and its pretty awful. I have tried changing the background color in the android layout xml. The closest one was I believe #drawable/white, but slightly changes the position and size of the edit text, making them look like they're one and its even worst.
Here is an example:
Is there a nice way to approach this problem? I read somewhere that an option was to add a white background image to the edit texts, but seemed like a lot of trouble.
UPDATE
I tried adding a background image, but its the same as changing the background color to any color using the android:background, the edit texts get like smaller or something. I added a blue "delimiter" to the image and this is the result:
But I want them like in the first picture, not so close one to another.
This would be the code of the edittext layout XML, the other one looks very similar. Only by adding the android:background tag changes from picture 1, to picture 3
SOLUTION
To solve this what I did was set a background image and set its height in dp as follows:
<EditText
android:id="#+id/markerTitle"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/buttonModifymarker"
android:ems="10"
android:inputType="textPersonName"
android:text="Título"
android:background="#drawable/editwhite"
>
Why don't you try setting the background of EditText programmatically?
yourEditText.setBackgroundColor(Color.WHITE);
or...
yourEditText.setBackgroundColor(Color.parseColor("#ffffff"));
simply you can add android:background="#drawable/white" attribute to your element in layout xml. you can use a lot of color resource between the double quotes (like from android color resources).
put the following image which has a solid white background in the drawable folder (it may dont appear because it's white and this page's background is white also) right click under this paragraph and select "Save Image as".
and refer to it in your layout and you will get a result like the following image
if the issue continue after trying this, please show me your layout code or email me at : mohamed_hamed4158#yahoo.com , thanks for voting my answer :)

How to get Android system Colors?

I'm searching way to get Android system colors - color theme used in device.
Using android:color/ I didn't get correct colors.
For example: background color in my device is BLACK, menu background color is DARKGREY.
Values from android:color/ in device is: only BLACK and WHITE backgrounds.
You can get android system color using
android:textColor="#android:color/black"
And this is working fine
Thanks for rekire :)
Finally I have the answer:
Android: How to get background color of Activity in Java?
TypedArray array = getTheme().obtainStyledAttributes(new int[]{android.R.attr.colorBackground,});
int backgroundcolor = array.getColor(0, 0xFF00FF);
It might just be setting a color filter on whatever the base color of the device is. That may be why you're not getting the base color you were expecting.
This is just a theory, I haven't verified it yet. Either that, or the base color for the theme you're looking is stored in a slightly different location. That's also a possibility.

How to get the default colors on Android

I have a custom component that I want to give the same colors as a TextView.
That is, I don't want to copy its colors, I want to get the default background and foreground colors, if there's such a concept on android.
[Edit]
The following seems to yield the text color of my TextView. But is it just luck? It's not intuitive to me that a default TextView would use android.R.attr.textColorSecondary? And why does not resolveAttribute return the color directly?
TypedValue tv = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.textColorSecondary, tv, true);
Color holyColor = getResources().getColor(tv.resourceId);
[Edit]
I found the source code of TextView at android.git.kernel.org, but it seemed to contain a lot of referrences to com.android.internal.R, which I don't think I should use in my own code. I'm currently looking for some kind of evidence that TextView uses android.R.attr.textColorSecondary.
[Edit]
I found some kind of evidence at developer.android.com, in styles.xml that TextView uses android.R.attr.textAppearanceSmall. textAppearanceSmall is documented to default to "secondary text color".
I guess I was lucky after all, but I still don't like that little code snippet of mine.
What you're looking for are attributes. Attributes link widgets to styles. For example, android:background is what you'd set for a particular view, but there's attributes like android:panelBackground and android:windowBackground that you can use override to affect the system as a whole.
You should look through R.attr and then link to those attributes in your widget. There should be a number of them that are linked to TextView; it would make sense to download the Android source code and see which attributes are used.

Categories

Resources