Android black screen before Splash screen in Kitkat version - android

In my Android application I seen black screen before splash screen so that I
have customized app theme as follows:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- my custom theme. -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/splash1</item>
</style>
the following is work for API version 20 and below version but in kitkat version (API version 21) it open the my splash screen two times.
I could not get solution after working long time. Please help me on this.

I am getting blank screen and i found the issue that "A TaskDescription's primary color should be opaque", means you have to replace your colorPrimary and colorPrimaryDark to 6 digits,
example: if you take colorPrimary = #4D607D8B remove "4D" and finally it is #607D8B. you can refer this link: https://stackoverflow.com/a/29166908/2897365

Try this,
Add a theme with the same background you are using into your application tag in the manifest file to prevent the black screen to be drawn.
theme.xml
<resources>
<!-- Base application theme is the default theme. -->
<style name="Theme" parent="android:style/Theme" />
<style name="Theme.MyAppTheme" parent="Theme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/my_app_background</item>
</style>
</resources>
AndroidManifest.xml
<application
android:name="#string/app_name"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.MyAppTheme" >

Related

Action Bar android change height [duplicate]

I would like to change the action bar size. I have tried the following coding.
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
</style>
<style name="CustomActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<!-- <item name="android:background">#drawable/action_bar_style</item> -->
<item name="android:actionBarSize">15dp</item>
<item name="android:background">#drawable/header_bar</item>
</style>
But the action bar size didn't change. Is there another way? I am using api level 11.
Thanks.
Use height attribute, actionBarSize if for something else.
<item name="android:height">#dimen/bar_height</item>
Explanantion:
From source code of ActionBar:
mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
We can see that R.styleable.ActionBar_height is being used for height. Stylable property names are generated as component_attribute (If you have ever used a custom stylable view, you'd have notice this). Hence, Actionbar is the name of component and height is the name of the attribute to use. Since this is a system attribute, hence defined under android namespace.
Update Dec-2014:
AppCompat library is now provided to extend support for latest ActionBar (or Toolbar) and theme support to old android versions. Below is an example of such an application theme /res/values/styles.xml:
<resources>
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<!-- native widgets will now be "tinted" with accent color -->
<item name="colorAccent">#color/accent</item>
<!--Action bar style-->
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="android:height">#dimen/bar_height</item>
<item name="height">#dimen/bar_height</item>
</style>
<style name="AppTheme.ActionBar.TitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textSize">#dimen/bar_text_size</item>
<item name="android:textColor">#color/bar_text_color</item>
</style>
</resources>
This style can now be set as app theme by using android:theme="#style/AppTheme" in <application> tag of the AndroidManifest.xml.
Note the use of duplicate entries
<item name="android:actionBarStyle">
<item name="actionBarStyle">
The ones without android namespace are there for supporting both compatibility library and native attributes.Some of these attributes didn't exist under android namespace on older versions and belong to support library.
In some other places, you'll need to use app namespace (xmlns:app="http://schemas.android.com/apk/res-auto"), for example app:showAsAction="always" in menu xml files.
Update Apr 2015
AppCompat Library v22 is also available. Read through the article to know what's new.
Simply put actionBarSize item under MyTheme style, like this:
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarSize">15dp</item>
<item name="actionBarSize">15dp</item>
...
</style>
Explanation:
In R.styleable we see that R.styleable.Theme_actionBarSize is a styleable attribute defined at Theme level.
Also, from source code res/values/styles.xml we see how actionBarSize is used to set height:
<style name="Widget.ActionBar">
...
<item name="android:height">?android:attr/actionBarSize</item>
Add this to the custom theme style XML that you are referencing from your manifest file:
<item name="android:windowTitleSize">58dip</item>
For instance if your manifest file looks something like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
**android:theme="#style/AppTheme"** >
Your theme style should be -at least- like this:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowTitleSize">54dip</item>
</style>
S.D.'s solution does not work for me.
I used AppCompat v-21 library in my case.
And I just add
android:layout_height="#dimen/actionBarSize"
android:minHeight="#dimen/actionBarSize"
to my layout file and it works.
Make sure to add S.D.'s code to styles.xml and then add
android:theme="#style/thin_ab"
to the <application> element in the main manifest. (I'm a noob and it took me about 2 hours to find that out.)

Change button background color in entire project in Android

I'm making an Android app, but I cannot change the default background color of all buttons in the project.
The only way I can do it is by changing them one by one.
Is there any other way?
Set buttonStyle in your Theme.
like following:
(I assume that you use AppCompat)
In your style.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat">
...
<item name="buttonStyle">#style/YourButtonStyle</item>
<!-- For preview -->
<item name="android:buttonStyle">#style/YourButtonStyle</item>
</style>
<style name="YourButtonStyle" parent="#style/Widget.AppCompat.Button">
<!-- Set background -->
<item name="android:background">#drawable/your_button_drawable</item>
</style>
</resources>
In your AndroidManifest.xml:
<application
...
android:theme="#style/AppTheme" >

Can't change the Actionbar color when using the Style.XML (Holo Theme)

Hi,
I've been trying for a long time to change the actionbar color in a very simple basic program using the Android Studio - with no success.
I'm using my Samsung Galaxy S4 to test it. What's wrong?
My Manifest includes this line: android:theme="#style/AppTheme"
and the Style.xml is this one:
**<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light">
<!-- Customize your theme here. -->
</style>
<style name="MyActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#ff0000</item>
</style>**
change name in manifest
like this
#style/AppTheme to #style/MyActionBar

Android theme: Whole screen becomes white

I am doing a simple customization to my app where I want to add a custom background color to Action Bar. Here is my styles.xml in styles-v14 folder. (My app is targeting only SDK 14 and above).
If I simply uncomment this line and run my app , the whole screen becomes white except status bar while I expect the Action Bar background color to be of different color.
<!-- <item name="android:actionBarStyle">#style/WindowTitleBackground</item> -->
Any idea what is going wrong. Here is my App manifest:
<application
android:name=".App"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
styles.xml
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:listChoiceIndicatorSingle">#drawable/btn_radio_holo_light</item>
<!-- <item name="android:actionBarStyle">#style/WindowTitleBackground</item> -->
</style>
<style name="RadioButtonAppTheme" parent="android:Widget.CompoundButton.RadioButton">
<item name="android:button">#drawable/btn_radio_holo_light</item>
</style>
<style name="WindowTitleBackground">
<item name="android:background">#color/titlebackgroundcolor</item>
</style>
</resources>
Try adding parent attribute in your ActionBar style
<style name="WindowTitleBackground"> parent="#android:style/Widget.Holo.ActionBar"
<item name="android:background">#color/titlebackgroundcolor</item>
</style>

Setting Android Theme background color

I'm trying to modify the default background theme color, which should be easy but surprisingly I can't get it working. Please note that I want the change to be across the entire app, not just for a single activity. Here is my code:
styles.xml
<resources>
<color name="white_opaque">#FFFFFFFF</color>
<color name="pitch_black">#FF000000</color>
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:background">#color/white_opaque</item>
<item name="android:windowBackground">#color/white_opaque</item>
<item name="android:colorBackground">#color/white_opaque</item>
</style>
</resources>
and of course in the manifest
<application
.
.
.
android:theme="#style/AppTheme" >
</application>
Android doc which I consulted on modifying themes:
http://developer.android.com/guide/topics/ui/themes.html
I've tried switching between white_opaque and pitch_black for all the xml attributes but it doesn't change a thing. Any suggestions?
Okay turned out that I made a really silly mistake. The device I am using for testing is running Android 4.0.4, API level 15.
The styles.xml file that I was editing is in the default values folder. I edited the styles.xml in values-v14 folder and it works all fine now.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.NoActionBar">
<item name="android:windowBackground">#android:color/black</item>
</style>
</resources>
Open res -> values -> styles.xml and to your <style> add this line replacing with your image path <item name="android:windowBackground">#drawable/background</item>. Example:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.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:windowBackground">#drawable/background</item>
</style>
</resources>
There is a <item name ="android:colorBackground">#color/black</item> also, that will affect not only your main window background but all the component in your app. Read about customize theme here.
If you want version specific styles:
If a new version of Android adds theme attributes that you want to
use, you can add them to your theme while still being compatible with
old versions. All you need is another styles.xml file saved in a
values directory that includes the resource version qualifier. For
example:
res/values/styles.xml # themes for all versions
res/values-v21/styles.xml # themes for API level 21+ only
Because the styles in the values/styles.xml file are available for all
versions, your themes in values-v21/styles.xml can inherit them. As
such, you can avoid duplicating styles by beginning with a "base"
theme and then extending it in your version-specific styles.
Read more here(doc in theme).

Categories

Resources