I am creating an application where it needs to be in full screen all the time so that the status bar is not shown and the navigation back bar should show.
Here is what I am doing currently:
AndroidManifest.xml
<application
android:name="ApplicationClass"
android:allowBackup="true"
android:configChanges="locale|orientation|layoutDirection"
android:fullBackupContent="#xml/backup_descriptor"
android:hardwareAccelerated="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:largeHeap="true"
android:resizeableActivity="false"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="UnusedAttribute">
......
<activity
android:name=".HomePageActivity"
android:hardwareAccelerated="true"
android:screenOrientation="portrait">
<activity
android:name=".SplashScreen"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|layoutDirection"
android:hardwareAccelerated="true"
android:screenOrientation="portrait"
android:theme="#style/Theme.Transparent">
styles.xml
<!-- 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:layoutDirection">ltr</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:fontFamily">#font/roboto</item>
<item name="fontFamily">#font/roboto</item>
</style>
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:layoutDirection">ltr</item>
<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">#color/white</item>
<item name="android:windowExitAnimation">#android:anim/fade_out</item>
</style>
Splash Screen Activity Code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
overridePendingTransition(R.anim.noanim, R.anim.activity_fade_out);
HomePage Activity Code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
overridePendingTransition(R.anim.noanim, R.anim.activity_fade_out);
activity_home_page.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/cl_home_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bb_bottom_bar"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
The MAIN Issue:
Please help what am I doing wrong, I almost tried everything I could but couldn't get the solution. I just need the status bar to go away and the navigation bar to remain there it is with the bottom bar tab above my navigation bar.
Please help!!
Related
I am using Android Studio 3.2 and Android API 23 develop the app, when I try to set a custom title bar it display the error You cannot combine custom titles with other title features.
I google the the error and try some answers on so, but it can't solve the problem, I am stucked.
the code is as following,
the manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shashiwang.shashiapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity" android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
the styles:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowNoTitle">true</item>
<!--<item name="windowActionBar">false</item>-->
</style>
<style name="TitleBarLayout" >
<item name="android:background">#color/colorTitleBarBg</item>
<item name="android:layout_height">#dimen/title_bar_height</item>
<item name="android:layout_width">match_parent</item>
</style>
<style name="TitleBarTitle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:color">#color/colorTitleBarTitle</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:text">#string/app_name</item>
<item name="android:textSize">#dimen/title_bar_title_font_size</item>
<item name="android:textStyle">bold</item>
</style>
<style name="TitleBarContactLayout">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:orientation">vertical</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:gravity">center</item>
<item name="android:layout_marginRight">10dp</item>
</style>
<style name="TitleBarContactIcon">
<item name="android:layout_width">#dimen/title_bar_contact_icon_width</item>
<item name="android:layout_height">#dimen/title_bar_contact_icon_height</item>
<item name="android:src">#drawable/ic_contact</item>
</style>
<style name="TitleBarContactText">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:text">#string/title_bar_contact_text</item>
<item name="android:textSize">#dimen/title_bar_contact_font_size</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/titleBarContainer"
style="#style/TitleBarLayout">
<TextView
android:id="#+id/TitleBarTitle"
style="#style/TitleBarTitle" />
<LinearLayout
android:id="#+id/TitleBarContactContainer"
style="#style/TitleBarContactLayout">
<ImageView
android:id="#+id/titleBarContactIcon"
style="#style/TitleBarContactIcon" />
<TextView
android:id="#+id/TitleBarContactText"
style="#style/TitleBarContactText" />
</LinearLayout>
</RelativeLayout>
the activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar_layout);
}
I've made my app fullscreen with no title by writing following code
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
But I can open action bar and notifications bar as we usually do from top.
Is there any way to never show top action bar.
Fullscreen App:
Visible status bar:
As soon as I touch and slide down from top mobile status bar becomes visible. How to stop that ?
Updates:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sampleapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:stateNotNeeded="true"
android:theme="#style/AppTheme.Wallpaper">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".LockScreenActivity" />
</application>
</manifest>
styles.xml
<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>
</style>
<!-- THIS IS THE MAIN THEME -->
<style name="AppTheme.Wallpaper" parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowShowWallpaper">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
Use this code inside the style.xml
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
</style>
First, make these changes in the themes.xml file as shown below and then, in AndroidManifest.xml file add "android:theme="#style/FullScreen" this line in activity section.
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme._your_app_name" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
</style>
<style name="FullScreen" parent="Theme._your_app_name">
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
Don't forget to add "android:theme="#style/FullScreen" line in AndroidManifest.xml file under activity section.
Try this!
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
}
in style.xml:
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
</style>
in manifest application tag:
android:theme="#style/AppTheme"
I have removed the action bar for a specific activity and it is working perfectly and the action bar is removed when I run the app on Emulator/Device but the problem is that it is still showing in the preview. Due which It affects my design.
Here is my style file where I set the noAction bar:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<!-- Text Styles -->
<style name="textStyle">
<item name="android:textColor">#color/theme_color</item>
<item name="android:textSize">16sp</item>
</style>
<style name="textStyle.tagline">
<item name="android:textAllCaps">true</item>
<item name="android:textSize">46sp</item>
</style>
<!-- Button Styles -->
<style name="button_transparent">
<item name="android:textAllCaps">true</item>
<item name="android:textColor">#color/theme_color</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="button_blue">
<item name="android:textAllCaps">true</item>
<item name="android:textColor">#color/white</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
</resources>
I have also applied that style on activities as shown here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.eapple.karumber">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Splash_Screen" android:theme="#style/AppTheme.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".protips_activity" android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
</manifest>
But is still showing in the preview as shown here:
Android Studio preview
Fastest solution:
Open your activity's XML.
Switch to the design tab.
On the upper part of the design tab click on AppTheme.
Choose your new theme (the one with no action bar).
However
Adding this line to the activity XML root view should automatically reference to the same activity theme set in AndroidManifest
tools:context=".YourActivityName"
If this is only on the preview u can change the theme with an option on the top of the view. Just select you theme with NoActionBar
I have changed actionbar color and other things to open in required color and text but when I open the app: The app opens with default theme and immediately changes to given theme.
This happens in phones like Galaxy Nexus, Nexus 4 but not on Nexus 5. I am not sure why this is happening?
I have set the actionbar before setContentView in my APP
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(true);
getActionBar().setIcon(android.R.color.transparent);
getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionBarColor)));
setContentView(R.layout.activity_main);
}
I got the theme using: http://jgilfelt.github.io/android-actionbarstylegenerator/
My style which I got from the above looks like this:
<style name="Theme.link" parent="#android:style/Theme.Holo">
<item name="android:actionOverflowButtonStyle">#style/ThemeFor.OverFlow</item>
<item name="android:actionBarItemBackground">#drawable/selectable_background_link</item>
<item name="android:popupMenuStyle">#style/PopupMenu.link</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.link</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.link</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.link</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.link</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_link</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_link</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.link</item>
</style>
<style name="ActionBar.Solid.link" parent="#android:style/Widget.Holo.ActionBar.Solid">
<item name="android:background">#drawable/ab_background_textured</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_link</item>
<item name="android:backgroundSplit">#drawable/ab_background_textured_link</item>
<item name="android:progressBarStyle">#style/ProgressBar.link</item>
</style>
<style name="ActionBar.Transparent.link" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/ab_transparent_link</item>
<item name="android:progressBarStyle">#style/ProgressBar.link</item>
</style>
<style name="PopupMenu.link" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_link</item>
</style>
<style name="DropDownListView.link" parent="#android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_link</item>
</style>
<style name="ActionBarTabStyle.link" parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_link</item>
</style>
<style name="DropDownNav.link" parent="#android:style/Widget.Holo.Spinner">
<item name="android:background">#drawable/spinner_background_ab_link</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_link</item>
<item name="android:dropDownSelector">#drawable/selectable_background_link</item>
</style>
<style name="ProgressBar.link" parent="#android:style/Widget.Holo.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_link</item>
</style>
<style name="ActionButton.CloseMode.link" parent="#android:style/Widget.Holo.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_link</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.link.Widget" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu.link</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.link</item>
</style>
And I am calling the theme in Manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.link" >
<activity
android:name=".Link_Main"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Link_Support"
android:label="#string/action_support"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.ylg.linking.Link_Main" />
</activity>
</application>
Can somebody help me fix this?
Thanks!
Try to add <item name="android:actionBarStyle">#style/Theme.link</item> to your base Activity style in AndroidManifest.xml.
I think you should change a value for android:background in ActionBar.Solid.link to #color/actionBarColor.
This is happening because when the application run, it gets style from styles.xml so your default style would be visible to you and after that you are changing actiob bar in onCreate() so theme changes immediately. To solve this set the icon and background color of action bar using styles.xml only using below code.
Try it. Hope it works.
<style name="AppBaseTheme" parent="#android:style/Theme.Holo.Light">
.....
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" arent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/actionBarColor</item>
<item name="android:text">""</item>
<item name="android:icon">#android:color/transparent</item>
</style>
And remove below code.
getActionBar().setIcon(android.R.color.transparent);
getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionBarColor)));
I'm slowly moving my app to Android Lollipop, in fact I'm just beginning this process.
But I'm already having some problems. The first one is that I can't make the icon appear in the ActionBar again. Just the app name and buttons appear.
Here is my style:
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">true</item>
<item name="actionBarStyle">#style/MyApp.Widget.ActionBar.Solid</item>
<item name="actionBarTabStyle">#style/MyApp.Widget.ActionBarTabStyle</item>
<item name="actionModeBackground">#drawable/cab_background_top_MyApp</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_MyApp</item>
<item name="actionModeCloseButtonStyle">#style/MyApp.Widget.ActionButton.CloseMode</item>
<item name="actionBarItemBackground">#drawable/selectable_background_MyApp</item>
</style>
<style name="MyApp.Widget.ActionBar.Solid" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:logo">#drawable/ic_launcher</item>
<item name="background">#drawable/actionbar_background</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_MyApp</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_MyApp</item>
<item name="progressBarStyle">#style/MyApp.Widget.ProgressBar</item>
</style>
And here is my AndroidManifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:name=".MyApp"
android:theme="#style/AppTheme" >
<activity
android:name="com.br.myapp.MainActivity"
android:label="#string/explore"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
</activity>
</application>
And my activity class is extending ActionBarActivity from the AppCompat library v21.
Try adding the following two lines in onCreate of your main Activity:
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.your_actionbar_icon);