How to change a theme in Android Studio from NoActionBar to ActionBar - java

I started a project in Android Studio and apparently, the Theme was Theme.NameOfProject.NoActionBar.
This is causing a the following error :
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.weoutdoor/com.example.weoutdoor.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.app.ActionBar.setTitle(java.lang.CharSequence)' on a null object reference
The project themes.xml :
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.WeOutdoor" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<style name="Theme.WeOutdoor.NoActionBar">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.WeOutdoor.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.WeOutdoor.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
And the AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.weoutdoor">
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.WeOutdoor.AppBarOverlay"
tools:targetApi="31">
<activity
android:name=".RegisterActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="#style/Theme.WeOutdoor.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".UserProfileActivity"
android:exported="true"
android:theme="#style/Theme.WeOutdoor.AppBarOverlay">
</activity>
<activity android:name=".LoginActivity"
android:exported="true"
android:theme="#style/Theme.WeOutdoor.AppBarOverlay">
</activity>
</application>
I tried to change the style parent and theme to ThemeOverlay.AppCompat.Dark.ActionBar
but every time i try to use the code getSupportActionBar().setTitle("WeOutdoor");
I get the mentioned error above.
After trying to apply some of the suggestions in the answers to this post I ended up with a new error :
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
Currently my themes is as following :
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="MyTheme"
parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="windowActionBar">true</item>
And my AndroidMenifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.weoutdoor">
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/MyTheme"
tools:targetApi="31">
<activity
android:name=".RegisterActivity"
android:theme="#style/MyTheme"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="#style/MyTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".UserProfileActivity"
android:exported="true"
android:theme="#style/MyTheme">
</activity>
<activity android:name=".LoginActivity"
android:exported="true"
android:theme="#style/MyTheme">
</activity>
</application>
Keep in mind that in each activity.java i use getSupportActionBar();
My loginActivity that i highlighted in the error :
public class LoginActivity extends AppCompatActivity {
private EditText editTextLoginEmail, editTextLoginPwd;
private ProgressBar progressBar;
private FirebaseAuth authProfile;
private static final String TAG = "LoginActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.login_activity);
getSupportActionBar();
editTextLoginEmail = findViewById(R.id.editText_login_email);
editTextLoginPwd = findViewById(R.id.editText_login_password);
progressBar = findViewById(R.id.progressBar);
authProfile = FirebaseAuth.getInstance();
//Login Tab
Button buttonLogin = findViewById(R.id.button_login);
buttonLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String textEmail = editTextLoginEmail.getText().toString();
String textPwd = editTextLoginPwd.getText().toString();
if(TextUtils.isEmpty(textEmail)){
Toast.makeText(LoginActivity.this, "Please enter your email", Toast.LENGTH_SHORT).show();
editTextLoginEmail.setError("Email is required");
editTextLoginEmail.requestFocus();
} else if (!Patterns.EMAIL_ADDRESS.matcher(textEmail).matches()){
Toast.makeText(LoginActivity.this, "Please re-enter your email", Toast.LENGTH_SHORT).show();
editTextLoginEmail.setError("Valid Email is required");
editTextLoginEmail.requestFocus();
} else if (TextUtils.isEmpty(textPwd)){
Toast.makeText(LoginActivity.this, "Please enter your password", Toast.LENGTH_SHORT).show();
editTextLoginPwd.setError("Password is required");
editTextLoginPwd.requestFocus();
} else {
progressBar.setVisibility(View.VISIBLE);
loginUser (textEmail, textPwd);
}
}
});
It would be obvious in loginActivity.java that some lines were commented out and were causing the NPE.
All corrected and ActionBar is working fine.

You're trying to use a ThemeOverlay, which isn't the same as a full Theme. But, honestly, just stick with the NoActionBar theme and create your own toolbar at the top. It's just a layout containing a TextView for the title and some ImageButtons for icons.

Related

How to reduce Splash Screen time

It takes 7-10 seconds, I want to know there is a way to reduce the time. Before I installed the splash screen, the home page is loaded in 2-3 seconds. I have installed react-native-splash-screen package and configured the android files automatically by using #bam.tech/react-native-make.
Never tried on a real device, if you want to know.
MainActivity.java
package com.myApp;
import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
#Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashScreenTheme);
super.onCreate(savedInstanceState);
}
#Override
protected String getMainComponentName() {
return "myApp";
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myApp">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
splashscreen.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/splashprimary" />
<item>
<bitmap
android:gravity="center"
android:src="#drawable/splash_image" />
</item>
</layer-list>
styles.xml
<resources>
<style name="SplashScreenTheme" parent="SplashScreen_SplashTheme">
<item name="colorPrimaryDark">#color/splashprimary</item>
<item name="android:statusBarColor">#color/app_bg</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#000000</item>
<!-- Add the following line to set the default status bar color for all the app. -->
<item name="android:statusBarColor">#color/app_bg</item>
<!-- Add the following line to set the default status bar text color for all the app
to be a light color (false) or a dark color (true) -->
<item name="android:windowLightStatusBar">false</item>
<!-- Add the following line to set the default background color for all the app. -->
<item name="android:windowBackground">#color/app_bg</item>
</style>
</resources>
Try adding this in Style.xml
<item name="android:windowDisablePreview">true</item>
This will remove the white screen which appears in the start.

How to solve: IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

My app is failing to run in the emulator. The error cited is java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I've read a number of similar questions, including:
.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
ActionBarCompat: java.lang.IllegalStateException: You need to use a Theme.AppCompat
But none of these have worked.
The code in the res>values>styles.xml file is:
<resources>
<style name = "AppBaseTheme" parent = "TextAppearance.AppCompat">
<item name = "android:colorPrimary">#android:color/holo_blue_bright</item>
<item name = "android:colorPrimaryDark">#android:color/holo_blue_dark</item>
<item name = "android:colorAccent">#android:color/holo_red_dark</item>
</style>
</resources>
The code in the src>main>AndroidManifest.xml file is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.hbpm1">
<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/AppBaseTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I'd be very grateful if anyone could help :)
Application theme can not be <style name = "AppBaseTheme" parent = "TextAppearance.AppCompat">, because TextAppearance theme can't be used for Application theme at all. So, use any Theme.AppCompat as the default theme for your application.
For this, I can give an example:
<style name = "AppBaseTheme" parent = "Theme.AppCompat">
or
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
etc.
Hope it will work

howto get full screen activity in android studio

Am trying to make an splash screen and i want it to be full screen, no toolbar nothing, for that i changed the theme of the splashscreen.xml to full screen and in the design view everything seems perfect but when i launch the app on emulator it comes up again with the toolbar.
My androidmenifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shiftind.www.shiftind">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
android:label="#string/app_name"
android:launchMode="singleTask"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:screenOrientation="landscape" >
</activity>
<activity android:name=".MainActivity"></activity>
<activity android:name=".registration" />
<activity android:name=".login" />
<activity android:name=".SignUp" />
</application>
</manifest>
*My splashscreen.xml*
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_splash_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.shiftind.www.shiftind.SplashScreen"
android:background="#drawable/shiftind">
</RelativeLayout>
My SplashScreen.java
package com.shiftind.www.shiftind;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class SplashScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
Thread MyThread = new Thread(){
#Override
public void run() {
try {
sleep(3000);
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
MyThread.start();
}
}
Try defining the theme manually and setting the properties there. In themes.xml:
<style name="MyThemeNoBar" parent="#style/Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
And in AndroidManifest.xml, set the theme of SplashScreen to:
android:theme="#style/MyThemeNoBar"
Edit: I've also added android:windowFullscreen and android:windowContentOverlay (source: https://stackoverflow.com/a/25365193/3474282)
Your AndroidManifest was broken, here are corrections:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".SplashScreen"
android:label="#string/app_name"
android:launchMode="singleTask"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"></activity>
<activity android:name=".registration" />
<activity android:name=".login" />
<activity android:name=".SignUp" />
</application>
You could do this programmatically (see android samples):
public void toggleHideyBar() {
// The UI options currently enabled are represented by a bitfield.
// getSystemUiVisibility() gives us that bitfield.
int uiOptions = getActivity().getWindow().getDecorView().getSystemUiVisibility();
int newUiOptions = uiOptions;
boolean isImmersiveModeEnabled =
((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
if (isImmersiveModeEnabled) {
Log.i(TAG, "Turning immersive mode mode off. ");
} else {
Log.i(TAG, "Turning immersive mode mode on.");
}
// Immersive mode: Backward compatible to KitKat (API 19).
// Note that this flag doesn't do anything by itself, it only augments the behavior
// of HIDE_NAVIGATION and FLAG_FULLSCREEN. For the purposes of this sample
// all three flags are being toggled together.
// This sample uses the "sticky" form of immersive mode, which will let the user swipe
// the bars back in again, but will automatically make them disappear a few seconds later.
newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
getActivity().getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
}
In my case I am using below thing which is fulfill my requirement !!
In Activity use below code in Oncreate method
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
and in your set your style as below
<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>
</resources>
if still have confusion mention in comment please :-)

live wallpaper-settings button is not working

okay, this is my very first application which i am working on, everything works fine until i wanted to add a settings button to my live wallpaper, the problem is, when i simply hit "settings" it comes with this message of "live wallpaper picker has stopped". here's my code
Android manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Live.zaki"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.ui.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:exported="true"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android:label="#string/appName"
android:icon="#drawable/icon">
<service
android:name="com.Live.zaki.CustomWallpaper"
android:label="#string/appName"
android:permission="android.permission.BIND_WALLPAPER" >
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="#xml/wallpaper" />
</service>
<activity
android:name="com.example.ui.SecondActivity"
android:label="Home" >
</activity>
<activity
android:name=".PrefsActivity"
android:theme="#android:style/Theme.Black.NoTitleBar" >
</activity>
</application>
</manifest>
wallpaper.xml
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
android:thumbnail="#drawable/icon"
android:description="#string/appDescription"
android:settingsActivity="com.Live.zaki.PrefsActivity"
/>
prefs.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="#string/general_lwp_settings">
<CheckBoxPreference
android:key="lwp_o_scroll_lock_key"
android:summary="#string/lwp_o_scroll_lock_summary"
android:title="#string/lwp_o_scroll_lock_title"
android:defaultValue="false" />
<CheckBoxPreference
android:key="lwp_auto_animation_key"
android:summary="#string/lwp_auto_animation_summary"
android:title="#string/lwp_auto_animation_title"
android:defaultValue="false" />
</PreferenceCategory>
PrefsActivity.java
public class PrefsActivity extends PreferenceActivity{#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(com.Live.zaki.R.xml.prefs);
}
}
i haven't yet configured any preference logic on my main livewallpaper.java code, i just want that settings menu to popup "two checkbox in my case". Is this even possible ??
if anyone could help me, that would great !! tips, tutorials anything !!
here's my application results without settings,
https://drive.google.com/file/d/0B44QwXQHh5irNFRnYkhzdDhPM00/edit?usp=sharing
buddy add exported flag in setting activity and set it true android:exported="true"
change the package name in your xml folder wallpaper.xml file to a fully qualified name.
android:settingsActivity="yourPackagename.PrefsActivity"
in the Manifest file add:
<activity
android:exported="true"
android:name=".PrefsActivity"
android:theme="#android:style/Theme.Black.NoTitleBar">

Android: how to hide ActionBar on certain activities

I've developed a simple demo application with a splash screen a map and some regular screens.
I have an action bar at the top that contains a logo. It all looks fine on my phone (Galaxy s1 I9000 V2.3) but when i test it on Galaxy s2 v4 the action bar appears also in the splash screen and in the map screen.
The spalsh and map activity are not even inheriting from ActionBarActivity so how is that possible and how can i make it go away?
Manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:theme="#style/Theme.AppCompat.Light" >
<activity
android:name=".HomeActivity"
android:icon="#drawable/android_logo"
android:label=""
android:logo="#drawable/android_logo" >
<!--
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
-->
</activity>
<activity
android:name=".MapActivity"
android:label="" >
</activity>
<activity
android:name=".PackageActivity"
android:icon="#drawable/android_logo"
android:label=""
android:logo="#drawable/android_logo" >
</activity>
<activity
android:name=".SplashActivity"
android:label="" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MapActivity definition (it's a long one so i included just the definition):
public class MapActivity extends FragmentActivity implements LocationListener
Splash Activity:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
public class SplashActivity extends Activity{
private static final long SPLASH_DISPLAY_LENGTH = 2000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
Intent mainIntent = new Intent(SplashActivity.this,HomeActivity.class);
SplashActivity.this.startActivity(mainIntent);
SplashActivity.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
}
As you are asking about how to hide in a certain activity, this is what you need :
getSupportActionBar().hide();
Apply the following in your Theme for the Activity in AndroidManifest.xml:
<activity android:name=".Activity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
1.Go to your manifest.xml file.
2.Find the activity tag for which you want to hide your ActionBar and then add ,
android:theme="#style/Theme.AppCompat.NoActionBar"
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.NoActionBar"
>
If you want to get full screen without actionBar and Title.
Add it in style.xml
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
and use the style at activity of manifest.xml.
<activity ....
android:theme="#style/AppTheme.NoActionBar" > ......
</activity>
The ActionBar usually exists along Fragments so from the Activity you can hide it
getActionBar().hide();
getActionBar().show();
and from the Fragment you can do it
getActivity().getActionBar().hide();
getActivity().getActionBar().show();
This works for me! Put this in your Activity in manifests
<activity
// ...
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
// ...
</activity>
You can also make your custom theme in styles.xml like this:
<style name="Theme.MyCustomTheme" parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name = "android:windowActionBar">false</item>
<item name = "android:windowNoTitle">true</item>
// more custom...
</style>
Hope this help.
If you were using Theme.AppCompat.Light, a better equivalent would be Theme.AppCompat.Light.NoActionBar.
I found that using Theme.AppCompat.NoTitleBar caused my button text to be invisible so I am using Theme.AppCompat.Light.NoActionBar.
<activity android:name=".Activity"
android:label="#string/app_name"
android:theme="#android:style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
To hide the ActionBar add this code into java file.
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
You can use Low Profile mode
See here
Just search for SYSTEM_UI_FLAG_LOW_PROFILE that also dims the navigation buttons if they are present of screen.
Apply the following in your Theme for the Activity in AndroidManifest.xml:
<activity android:name=".DashboardActivity"
android:theme="#style/AppFullScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Then Apply the following in your Style in style.xml
<style name="AppFullScreenTheme" 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>
</style>
The above answers would help with the ActionBar thing. To add to it, use the following code in case you are using the Splash Screen:
Use this before you set the content view:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Just to clarify, here's how you do it:
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);         
setContentView(R.layout.activity_main);
This would make your screen a full screen, i.e remove the top bar where you see the network bar, etc
#Override
public void onResume() {
super.onResume();
getSupportActionBar().hide();
}
#Override
public void onStop() {
super.onStop();
getSupportActionBar().show();
}
For selectively hiding Actionbar in activities:
Add the following code to onCreate (preferably on the last line of the function)
Kotlin:
supportActionBar?.hide()
Java:
getSupportActionBar().hide();
This works in API 27
In the styles.xml replace code to the following....
<resources>
<!-- No Action Bar -->
<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>
</resources>
Then in the files (eg. activity_list.xml) in which you do want to have a toolbar put the following code.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/colorPrimary"/>
If you have problems switch to linear layout (because that is what this code is tested on)
From here:
Beginning with Android 3.0 (API level 11), all activities that use the default theme have an ActionBar as an app bar. However, app bar features have gradually been added to the native ActionBar over various Android releases. As a result, the native ActionBar behaves differently depending on what version of the Android system a device may be using. By contrast, the most recent features are added to the support library's version of Toolbar, and they are available on any device that can use the support library.
So one option is to disable ActionBar completely (in the app manifest.xml file) and then add Toolbar in every page that needs an ActionBar.
(follow the above link for step-by-step explanation)
Add New Style in your style.xml
<!-- 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="LoginTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
and then add following line in your manifest
<activity android:name=".Login"
android:label="#string/app_name"
android:theme="#style/LoginTheme"
>
If you activity extends AppCompatActivity then you can add this line
super.getSupportActionBar().hide(); before setContentView()
Replace AndroidManifest.xml
android:theme="#style/FullscreenTheme"
to
android:theme="#style/Theme.Design.NoActionBar"
Check for padding attribute if the issue still exists after changing theme.
Padding Issue creating a white space on top of fragment window / app window
Once you remove the padding - top value automatically the white space is removed.
First cheek MainActivity for activity tag,Like -
public class MainActivity extends AppCompatActivity
Then goto menifest xml file and write-
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
in activity tag

Categories

Resources