Enter full-screen during splash-screen activity - android

I am currently trying to go full-screen during my splash-screen Activity. I am doing that with a style, which is set on the Activity like this:
style.xml
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
AndroidManifest.xml
<activity
android:name=".Activities.SplashScreenActivity"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You might suggest doing that programmatically, but I already tried all the answers from this, this, this, this, this and this link. Currently, none of the programmatic solutions work for me - put every suggested fix in either onResume or onCreate of my splashActivity.java, but the status and navigation bar were still visible. However, when using my custom style it hides only the status bar, the navigation bar stays visible. What I've tried so far in the xml files: used different parents of the style, used no background drawable, removed screenOrientation and noHistory from activity. I am pretty sure I'm missing something here, but I can't see what. Can share more code if needed. Thanks in advance!

Here my SplashScreenActivity style:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_logo_drawable</item>
</style>
I only use the attribute windowBackground

Related

Get rid of white screen at startup

I've been searching online for the right way to avoid the white screen - replacing it with a splashscreen - when my Android app launches.
I found solutions that uses styles like
<style name="AppTheme.SplashTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
But in my case this only delays the view appearance, acting as the app doesn't work (the view inflates after a couple of seconds). I do not want some view that lasts for some seconds I've decided, I just want to replace the blank screen to something custom while my app needs to load.
The only way to have the desired behaviour was to place a drawable as a background in the style of my SplashscreenActivity.
<item name="android:windowBackground">#drawable/background_splash</item>
Now, I would like not to place an image as a background-because of the different resolutions of screens- but to set an xml layout.
Is this possible? What's the best way to get rid of the blank screen without delaying the view appearance?
You should do it as follows
create an xml file in res/drawable folder with below content. This will act as your splash screen. Let's name it splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorPrimary" />
<item>
<bitmap android:src="#drawable/splash_logo"
android:gravity="center" />
</item>
</layer-list>
Then you need to specify a style/theme without titlebar for your splash view, so add below style to your style.xml file.
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash</item>
</style>
In AndroidManifest.xml change theme of your launcher activity to use SplashTheme
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Finally in that launcher activity (in my example MainActivity) change the theme back to default application theme, usually named AppTheme
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme)
super.onCreate(savedInstanceState);
...
}
That's it! Now run your application and see that there is no white screen anymore.
References: I used this post and this one to provide the above code example.

Second App Bar in Android

As seen below, my application currently has a second App Bar that stacks below the second. And the unfortunate part is I have absolutely no idea how it is happening, as this has happened as a result of a merge by Git, so I have no idea what code is the offender.
The reason the above bar is a different colour is the bottom bar is the colour it is initially, declared in the xml file, but then I changed the colour of the top programatically to confirm there are two bars and it isn't just a size problem.
I'm aware that since I can't really post any code due to the lack of any ideas as to the source of the error this is a bit of a shot in the dark, however is there anything I should check to try determine the cause?
And yes, application theme has the app bar disabled. The really funky thing as well is if I extend my base UI class to another activity so it has the App Bar as well, only one bar is displayed, see below.
EDIT: As per request.
Manifest:
</activity>
<activity
android:name=".Activities.MainActivity"
android:label="Page Title"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.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:actionBarStyle">#style/MyActionBar</item>
<item name="windowActionBar">false</item>
<!--<item name="windowNoTitle">true</item>-->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.MainActivity);
use this.requestWindowFeature(Window.FEATURE_NO_TITLE); to hide the
title Bar
if you want show like first top image then make layout for that
imnstead of using two different appBar

Custom PopupMenu styles are being ignored

I've been struggling with PopupMenu styling, and after a lot of research, the process of creating a custom PopupMenu style for my theme seemed to be fairly straightfoward. For example the answer on this question seems like an easy way to change the background color of a PopupMenu. However, none of these solutions have worked for my project. So I started digging into the style sources to find out what I should actually be inheriting to style the PopupMenu in my own project.
I'm running my tests on a handset running API 19, and my base theme looks like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- ... -->
<item name="android:popupMenuStyle">#style/CustomPopupMenu</item>
</style>
<style name="CustomPopupMenu" parent="#style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#color/retina_burning_hot_pink</item>
</style>
This is the solution that most of the accepted answers here show. But this does not style my PopupMenu. So I dug into the sources to find the geneology of my theme and see what default settings where being used. This is what I found:
<style name="Theme.AppCompat.Light.DarkActionBar" parent="Base.Theme.AppCompat.Light.DarkActionBar"/>
<style name="Base.Theme.AppCompat.Light.DarkActionBar" parent="Base.Theme.AppCompat.Light">
<style name="Base.Theme.AppCompat.Light" parent="Base.V7.Theme.AppCompat.Light"/>
And then in Base.V7.Theme.AppCompat.Light I found these default settings:
<!-- Popup Menu styles -->
<item name="popupMenuStyle">#style/Widget.AppCompat.Light.PopupMenu</item>
<item name="textAppearanceLargePopupMenu">#style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Large</item>
<item name="textAppearanceSmallPopupMenu">#style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Small</item>
<item name="listPopupWindowStyle">#style/Widget.AppCompat.ListPopupWindow</item>
<item name="dropDownListViewStyle">?android:attr/dropDownListViewStyle</item>
So as far as I can tell, my theme inherits from Theme.AppCompat.Light.DarkActionBar which uses a default PopupMenu style of #style/Widget.AppCompat.Light.PopupMenu. I then inherit that style to set my own PopupMenu settings. I made sure my Activity and my Application are all using the correct Theme. I'm not sure why else this just won't work. I've also tried these settings:
<item name="android:textAppearanceLargePopupMenu">#style/CustomPopupMenuLarge</item>
<item name="android:textAppearanceSmallPopupMenu">#style/CustomPopupMenuSmall</item>
<item name="android:popupWindowStyle">#style/CustomPopupMenuListWindow</item>
I provided custom styles for each one, and none of them worked. What could be overriding all my custom styles? Any help would be appreciated, because I'm stumped.
EDITS
Here's my manifest...
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blah.blah">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".Activities.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is AppTheme.NoActionBar
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Do not specify android: in
<item name="android:popupMenuStyle">#style/CustomPopupMenu</item>.
Instend:
<item name="popupMenuStyle">#style/CustomPopupMenu</item>
I think you need to define a parent for AppCompat.NoActionBar. Try parent="Theme.AppCompat.Light.NoActionBar" and also add in <item name="android:popupMenuStyle">#style/CustomPopupMenu</item> to it.

Applying style globally Android with theme and Style inheritance

I am trying to create base theme for whole my app, I have created custom styles for base components like EditText, Button, TextView and wanna to set them globally in my app.
Here is my xml code.
<style name="AppThemeBase" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/base_app_color</item>
<item name="colorPrimaryDark">#color/base_app_color</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:editTextStyle">#style/EditTextBaseStyle</item>
<item name="android:textViewStyle">#style/TextViewBaseStyle</item>
</style>
My custom edit text style
<style name="EditTextBaseStyle" parent="Widget.AppCompat.EditText">
<item name="android:textColor">#color/base_text_color</item>
<item name="android:textSize">#dimen/text_size_edit_text</item>
<item name="android:textColorHint">#color/base_hint_color</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:background">#drawable/edit_text_rounded_corners_bg</item>
</style>
I also tried to use #android:style/Widget.EditText as a parent.
<style name="TextViewBaseStyle" parent="#android:style/Widget.TextView">
<item name="android:textColor">#color/base_text_color</item>
<item name="android:textSize">#dimen/size_text_base</item>
<item name="android:layout_margin">#dimen/margin_text_view_base</item>
</style>
And of course in AndroidManifest.xml file
<application
android:name=".application.QrApplication"
android:allowBackup="true"
android:icon="#drawable/ic_logo_green"
android:label="#string/app_name"
android:theme="#style/AppThemeBase">
<activity
android:name=".ui.activities.LoginActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name"
android:noHistory="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I have several questions
Why it doesn't apply style for each view (EditText and TextView), if set style manually in xml layout it works like a charm, but I cannot get it working globally
About style inheritance. There are two types of inheritance explicit or implicit or for user custom styles using . (dot) and using keyword parent for default themes, but what will be if combine this types of inheritance like this <style name="SomeStyle.ParentStyle" parent="Widget.AppCompat.Button">?
Are styles and theme applied to fragments inside activity, theoretically it should because for inflating fragment context from activity is used which is ContextWrapper ?
Please if you have any ideas what can cause such problem, help to solve it or at least share your thoughts.
Thanks.
The problem was solved
Instead of overriding
<item name="android:editTextStyle">#style/EditTextBaseStyle</item>
I have to override
<item name="editTextStyle">#style/EditTextBaseStyle</item>
To figure out what style item you need to override, follow the inheritance tree of base style/theme and you will find what is the name of style item you need to use.
BUT NOTE
Text view style should be still
<item name="android:textViewStyle">#style/TextViewBaseStyle</item>
It is weird but as is.

Custom Home Icon in Action Bar Sherlock

I am trying to set custom icon for home icon using ActionBarSherlock library. I have tried to set custom layout using abHomeLayout attribute in my custom theme. But it didn't work for me. Only way, how to set it, is to set abIcon attribute for my custom drawble, but I cannot set some horizontal padding for this drawable. Is there any example for this or where could be a problem with abHomeLayout attribute?
This works for my situation, it replaces the default ic_launcher icon in the action bar with my custom one.
In your onCreate do this:
getSupportActionBar().setIcon(R.drawable.audio_shortcut);
Or in the manifest you can set the logo:
<activity>
android:logo="#drawable/my_custom_logo"
...
</activity>
This works great too:
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="icon">#drawable/my_custom_logo</item>
<item name="android:icon">#drawable/my_custom_logo</item>
</style>
Reference: How to change the ActionBar “Home” Icon to be something other than the app icon?
I had similar issue with incorrect padding of the home icon on devices api<11 (i.e not the fully fledged platform action bar) and the abHomeLayout style only worked api>11
My solution was to copy the abs__action_bar_home.xml layout from ABS to child project and manually add padding to the abs__home imageview
<ImageView
android:id="#+id/abs__home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="#dimen/action_bar_home_icon_top_bottom_padding"
android:paddingBottom="#dimen/action_bar_home_icon_top_bottom_padding"
android:paddingLeft="#dimen/action_bar_home_icon_left_right_padding"
android:paddingRight="#dimen/action_bar_home_icon_left_right_padding"
android:scaleType="centerInside" />
Define an own style, like this:
<resources>
<style name="Theme.OwnTheme" parent="#style/Theme.Sherlock">
<item name="abBackground">#476dd5</item>
<item name="abHeight">30dip</item>
</style>
</resources>
I think here your can use abHomeLayout.
Set this style for your activity like this:
<activity
android:name=".MainActivity"
android:theme="#style/Theme.OwnTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In MainActivity you can use getSupportActionBar()... functions.

Categories

Resources