How would I implement a monochrome icon like other google apps so that it matches the dynamic colours picked by Material You?
Open your app icon and add the monochrome android:drawable attribute to the <adaptive-icon> element. For example, in res/mipmap-anydpi-v26/ic_launcher.xml:
<adaptive-icon >
<background android:drawable="..." />
<foreground android:drawable="..." />
<monochrome android:drawable="#drawable/mymonochromeicon" />
</adaptive-icon>
If your try this and it does not work then you need to remove the android:roundIcon element from your AndroidManifest.xml, or, alternatively, also add the <monochrome android:drawable="#drawable/mymonochromeicon"/> tag to your round icon.
Android Studio might give a warning saying Element monochrome is not allowed here however we can ignore this.
Related
Assuming this is my app icon
It works fine in Android 11 (and below)
but when I install the app in Android 12, there is a white border around the icon in the splash screen (also a black border around the top app icon.)
Is there any way I can remove those borders?
below is my splash code
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#color/colorBlack"/>
<item>
<bitmap
android:src="#drawable/notice"/>
</item>
</layer-list>
Also this line in my AndroidManifest.xml
android:roundIcon="#drawable/notice"
There seems a misusage in your terminology splash screen. It should be called Recents screen in the screen shots.
So this is not a problem about Splash screen. This should be a problem about a launcher icon using Adaptive icon.
By default, in template projects on Android Studio, the launcher icons in the Manifest are:
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
And both of mipmaps are:
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="#drawable/ic_launcher_background" />
<foreground android:drawable="#drawable/ic_launcher_foreground" />
</adaptive-icon>
Lastly, both of these ic_launcher_foreground and ic_launcher_background are vector drawables. (note that you can also use #color instead of a vector drawable)
As you can notice, layer-list or bitmap is not used. You can use an Adaptive icon on API-26+.
I have created a rounded icon for my app with name ic_launcher.png. I read that I must have ic_launcher_round.png too.
Why do I need that as my icon is already rounded. Will removing that cause any problem ? Can I remove this line also from andrid_manifest.xml ?
android:roundIcon="#mipmap/ic_launcher_round"
After Android 8.0 (API level 26) you can use adaptive launcher icons.
To add an adaptive icon to an app using XML, begin by updating the android:icon attribute in your app manifest to specify a drawable resource. You can also define an icon drawable resource using the android:roundIcon attribute. You must only use the android:roundIcon attribute if you require a different icon asset for circular masks.
You can also define the background and foreground drawables as elements by enclosing them in and elements.
A simple way to generate a adaptive icons is in Android Studio.
Select App folder -> right click -> New -> Image Asset
Sample Image
Sample Icon
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="#drawable/ic_launcher_background" />
<foreground android:drawable="#drawable/ic_launcher_foreground" />
</adaptive-icon>
You might be thinking this question is a duplicate of this one. But since then, Android Studio has been updated and the solution given there is not working anymore.
Why are we forced to have a background when creating an Image Asset? What's the reason behind this? How we are supposed to change the launcher_icon without having any background? I don't see any option to disable the background in Image Asset.
Alternatively, I use an empty background but this doesn't work in Full Bleed Layers:
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108"
xmlns:android="http://schemas.android.com/apk/res/android">
</vector>
Or, just remove the background, but this will add a white background in your launcher_icon:
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Remove the background here and leave the foreground -->
<foreground android:drawable="#drawable/ic_launcher_foreground"/>
</adaptive-icon>
Or, change icon type into Legacy Only and set shape to none:
Still, there's a white background in the launcher icon when installed.
So how can I get a transparent background or none for that matter, for my Launcher icon using Image Asset?
It is not a problem of the icon you created with Android Studio, but it's a problem related to your specific device you're testing the application on.
In fact, in the Image Asset if you specify the Shape to None, you get a trasparent background.
To address your problem, please try to use a different Home theme, like the Nova Launcher; you can change the home theme in Settings - Home.
I've seen there are many different "themes" for the Android, depending on the device. For example on my HTC WildFire the highlight color is a "lime green", and that of the emulator is orange.
Is there anyway to know what are the main interface colors of the device in which my app is running?
So i can set (for example) TextViews background colors to match the device theme.
EDIT: You told me this is not possible so...
Is there any way to draw a simple rectangle with the highlight color? Maybe a void button?
Thanks!!
It's not actually a specified color, the drawables themselves are actually replaced on these modified Android skins that HTC, Samsung, etc. put out. So programmatically, there's no direct way to know what the color scheme will be. Your best bet would be to simply define your own drawables for your widgets with your own color scheme, or even reuse the defaults from stock Android, but copy them to your app's drawable folder, and set them into a StateListDrawable, and apply these to your widgets. This will ensure that you get the same color style on all platforms, with the disadvantage being that your app will not match the scheme of the rest of the skin. Depending on your app's layout, that will likely not be a problem, though.
I don't think that there is a way for you to get what the default highlight color is but you can certainly set your own by using the "textColorHighlight=#aarrggbb" attribute on your TextView within the layout.
As far as I know, there isn't a way (I don't see how there could be really). I guess you could have a few different "themes" in your own app and let the user pick one, to easily atleast somewhat match the rest of their setup.
You can use the #android:drawable/list_selector_background (or code form: android.R.drawable.list_selector_background) on your views. It has each of the default selector states. You can also create a selector yourself in the drawable folder like this (named something like default_highlight.xml):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#android:drawable/list_selector_background" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="#android:drawable/list_selector_background" /> <!-- focused -->
<item android:drawable="#android:drawable/list_selector_background" /> <!-- default -->
</selector>
And change any of those that you might want to customize. Then you use it like any drawable by setting the background of a View to that (default_highlight or whatever you call it).
I'm trying to detect the focus/pressed color for button and other elements.
This is needed because I'm developing new components and it's important that those look as part of platform.
Those colors are ORANGE on android sdk and GREEN on HTC SenseUI.
If I could detect that color my component will look as part of platform on both version.
Does anyone knows how to do this?
It's possible to create "selector" which uses custom image for default state and platform default for focus/selection.
To do this follow the steps:
1) create xml file with selector in "res/drawable" (e.g. "red_button.xml"):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#android:drawable/btn_default" >
</item>
<item android:state_focused="true"
android:drawable="#android:drawable/btn_default" >
</item>
<item
android:drawable="#drawable/btn_default_red" >
</item>
</selector>
2) from folder ".../android-sdk-mac/platforms/android-1.5/data/res/drawable/" take picture "btn_default_pressed.9.png" and change color as you like (I needed to change it to red and for this GIMP is enough).
3) place altered picture in "res/drawable" (e.g. with name "btn_default_red.9.png")
4) define button:
<Button
android:id="#+id/info_button"
android:layout_width="wrap_content"
android:layout_height="37dip"
android:layout_marginTop="1dip"
android:background="#drawable/red_button"
android:text="[Info]" />
That's all.
This is result:
alt text http://img200.imageshack.us/img200/1349/custombutton.png
I had this problem too. As already stated, the problem is that the backgrounds aren't simple colors, they're Drawables that could take on all kinds of appearances. However, I found a work-around that may help. If your custom component looks something like an existing one, e.g. a Button or ListView entry, you can just steal their background/selector and set that as the background for your custom component. E.g., in your custom component constructor:
setBackgroundDrawable(new Button(context).getBackground());
or for a background more suitable for list-like components:
setBackgroundDrawable(new ListView(context).getSelector());
You may want to optimise that code somewhat, but you get the idea.
Those aren't colors. They are a few nine-patch images out of a StateListDrawable. I am skeptical that there will be a reliable way for you to determine what the color is, one that will work across all devices and all versions of Android.
This is pretty much a duplicate of: Android ListView Selector Color
Also, why do you need to detect the colours? Just do nothing and your widgets will fit in to the platform's existing look & feel.
Or if you're writing a custom theme, just make yours inherit from android:Theme.