Transparent 9-patch over colored background - android

I'm trying to create a splash activity that uses a 9-patch image that is transparent apart from my app's logo. Consequently, I would like to set the background color of the window to show through behind my logo. However, no matter what I do, it seems that the background is insisting on being black.
I've tried setting both background and colorBackground:
<style name="Splash" parent="android:Theme">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:background">#android:color/white</item>
<!--
<item name="android:colorBackground">#android:color/white</item>
-->
<item name="android:windowNoTitle">true</item>
</style>
But neither works when windowBackground is also set.
How can I set the background color of my splash activity so that transparency in my 9-patch image is filled in correctly?

I tested your code, and I found that in your style I can specify android:windowBackground, android:background, or android:colorBackground, but not more than one at the same time.
I was successful in using a color for the background in the styles.xml, and then specifing the image in the regular layout XML, using an alpha property for transparency.
Styles.xml example:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:colorBackground">#android:color/holo_blue_bright</item>
</style>
</resources>
layout.xml example:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:alpha="0.5"/>
I have the style set in the AndroidManifest.xml under the application section:
android:theme="#style/AppTheme"

Related

How can I use dynamic colors in SplashScreen api an android 12?

I'm trying to make the background of an android 12 splash screen use #android:color/system_neutral1_900 as the background, but as I can see, the color loads only after the splash screen. Is there any way to use it on the splash screen?
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
<!-- Set the splash screen background, animated icon, and animation duration. -->
<item name="windowSplashScreenBackground">#android:color/system_neutral1_900</item>
</style>
The color does not appear and it uses the default grey. I also tried with other system_ colors and the same result comes up. Using #android:color/black or hex colors works.
Try using this item as part of your main application theme according to this link
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowSplashScreenBackground">#color/colorAccent</item>
</style>

How to prevent the textColor from changing with the Dark Mode of the smartphone in AndroidStudio? [duplicate]

I'm using Theme.AppCompat.DayNight and I want to customize a certain layout background and text color to change depending on whether it's day or night mode .
Here's what I tried so far:
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primaryDarkColorAmber</item>
<item name="colorPrimaryDark">#color/primaryDarkColorAmber</item>
<item name="colorControlActivated">#color/primaryDarkColorAmber</item>
</style>
<style name="PopUpTheme" parent="AppTheme">
<!-- layout custom theme there's no darkBackground value...!! -->
<item name="android:background">#color/popup_background</item>
</style>
first of all create res/values-night this directory then add same as res/value file you can copy and replace to color and after that when you change day or night theme you can get color according to your style
If you are following Android's Color theming System, then you can use:
<View
...
android:background="?android:attr/colorBackground"
.../>
Similarly, for texts you can use ?android:attr/textColorPrimary and for icons ?attr/colorControlNormal. This way you do not need to create separate value files.
You can find more details here.

How to apply style to all Buttons but not to ImageButtons?

I need to apply a background color to all the buttons in my application, so I added this to styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- button styles -->
<item name="colorButtonNormal">#color/button_color</item> <!-- below api 21 -->
<item name="android:colorButtonNormal">#color/button_color</item> <!-- above api 21 -->
<item name="android:buttonStyle">#style/ButtonColor</item>
</style>
<style name="ButtonColor" parent="#style/Widget.AppCompat.Button">
<item name="android:textColor">#color/font</item>
</style>
It worked perfectly, when I add a button in XML, the button has automatically the colors I set in styles.xml
The problem is that when I add a ImageButton, the ImageButton is getting also those colors, and I don't want that. The problem is specifically with colorButtonNormal, which applyes the background color to the ImageButton also and I don't want that. How can I solve this problem?
The default style used by the ImageButton (in your case AppCompatImageButton) is defined in the app theme by the attr:
<item name="imageButtonStyle">#style/Widget.AppCompat.ImageButton</item>
In this style the background attribute <item name="background">#drawable/btn_default_material</item> is tinted with the android:tint="?attr/colorButtonNormal".
You can use a custom style starting from btn_default_material for the ImageButton or you can override the color in the layout.
Something like:
<ImageButton
android:theme="#style/MyImageButtonTheme"/>
with something like:
<style name="MyImageButtonTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="colorButtonNormal">#color/my_color</item>
</style>
Also evaluate to migrate to Material Components and the MaterialButton.
In this case it is very simple to override the color just using the styles:
<style name="MyButtonTheme" parent="Widget.MaterialComponents.Button">
<item name="materialThemeOverlay">#style/ButtonStylePrimaryColor</item>
</style>
<style name="ButtonStylePrimaryColor">
<item name="colorPrimary">#color/....</item>
</style>
You can do it by applying different style for defferent views
Let's say i have three style with defferent color combination and i wish to apply bigButtonTheme style for all big button
Then
i add this line on all big button android:theme="#style/bigButtonTheme">
Rest button or other vewis will remain unchanged.
You can also copy other properties of a style like global themes font background color by deffineing as parents theme
<style name="ButtonColor" parent="#style/GlobelStyleOfApp"/>

How can I apply a transparent background to the windowBackground

I have created a simple image using Inkscape with a transparent background, alpha(0) and at the center, I have a small logo. I then applied it to my styles like below:
<style name="SplashScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">#drawable/splashscreen</item>
<item name="colorPrimary">#android:color/transparent</item>
<item name="colorPrimaryDark">#color/colorPrimary</item>
<item name="colorAccent">#color/loginHeaderBackground</item>
</style>
It works fine, however, I'm missing my main objective, its displaying a black screen with the middle icon instead of a transparent one.
What I want (User should be able to still see their phone background when the app starts to launch)
What I'm getting
Why is this?
There is an example for you. I wrote custom theme and i added this theme to my activty. You should add this your splash activity in manifest file.
<activity ...
android:theme="#android:style/Theme.TranslucentTheme"
.../>
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TranslucentTheme" parent="android:Theme.Translucent">
<item name="android:windowBackground">#color/transparent_black</item>
</style>
<color name="transparent_black">#DA000000</color>
</resources>

Android Custom Theming in ActionBar/Tabs

I have the theme Holo.Light.DarkActionBar
The tabs are now set to white background, light gray text--very unreadable. I simply want to change the text to something much, much darker.
I have searched the styles to see if I can override but all I can do is change the background, not the text.
Can I do this in the styles.xml or do I have to do this programmaticly?
If you're referring to the ActionBar's tab see if this changes the color:
<!-- The theme for the activity -->
<style name="TabSpecialTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="#android:attr/actionBarTabTextStyle">#style/TabStyle</item>
</style>
<!-- Modify the text color -->
<style name="TabStyle" parent="android:Widget.Holo.Light.ActionBar.TabText.Inverse">
<item name="android:textColor">#F70000</item>
</style>
Of course don't forget to set the theme for the activity to #style/TabSpecialTheme in the manifest.

Categories

Resources