How can I hide the title Bar from the activity_main layout? I have android studio 1.3.1 and I used the android:theme="#android:style/Theme.NoTitleBar.Fullscreen" within the activity tag but when I see the activity_main again I see the title Bar or the same action Bar again. How can I hide it?
Put this code below the AppTheme in your styles.xml file whixh is in values directory.
<style name="MyThemeNoTitle" parent="AppTheme">
<item name="android:windowNoTitle">true</item>
</style>
And in your Manifest.xml file put theme tag to your activity as,
<activity
android:name="MainActivity"
android:label="#string/app_name"
android:theme="#style/MyThemeNoTitle">
You can define this theme with no ActionBar and which is also supported in all Android versions:
<style name="Base.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
After you can apply this theme as the theme of the entire application or just for your MainActivity in the manifest with the attribute android:theme
Related
I know how to set the status bar color across my app using style.xml but how do I change it on different activities?
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorBlack</item>
<item name="colorPrimaryDark">#color/colorBlack</item>
<item name="colorAccent">#color/colorBlueLight</item>
</style>
You can create multiple custom themes and assign them to each Activity on AndroidManifest.xml such as:
<activity android:theme="#style/CustomTheme1">
<activity android:theme="#style/CustomTheme2">
You can define a second theme in your styles.xml:
<style name="AppTheme.Secondary">
<!-- set your attributes here -->
</style>
And then, in your AndroidManifest.xml, set your other activity to use the other theme:
<activity
android:name=".YourSecondActivity"
android:theme="#style/AppTheme.Secondary"/>
If i use AppTheme without ActionBar than i get crash when i call WeAccept Payment SDK because they require Actionbar to be available in AppTheme.
My code :
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="colorPrimary">#color/DefaultPrimary</item>
<item name="colorPrimaryDark">#color/DefaultPrimaryDark</item>
<item name="colorAccent">#color/DefaultAccent</item>
<item name="android:textColorHint">#color/DefaultPrimary</item>
<item name="android:actionButtonStyle">#style/MyActionButtonStyle</item>
<item name="android:typeface">serif</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
And in Manifest
i use android:theme="#style/AppTheme.NoActionBar"
Note : i cant display the default ActionBar in my application because if the custom design
With himanshu help i managed to get it working after creating new theme with different name in styles and adding that sdk activity in my main manifest (it seems that it will override their manifest).
<activity
android:name="com.paymob.acceptsdk.PayActivity"
android:theme="#style/AppThemePayment" />
my main activity extendeds AppCompatActivity. i cannot see anything wrong with these codes but my action bar color still doesn't change. help?
styles.xml
<style name="CustomTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/CustomActionBarStyle</item>
</style>
<style name="CustomActionBarStyle" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#008000</item>
</style>
AndroidManifest.xml (i use a splashscreen that's why .MainActivity is not my launcher)
<activity
android:name=".MainActivity"
android:theme="#style/CustomTheme">
<intent-filter>
<category android:name="android.intent.category.default" />
</intent-filter>
</activity>
Just modify the styles.xml as follow:-
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#FF9800</item> // This will be the color of your Actionbar
<item name="colorPrimaryDark">#FF9800</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorButtonNormal">#FF9800</item>
</style>
Please check this to see which color values you should set/override in your application/activity theme.
<item name="android:colorPrimary">#color/primary</item> will be for color of action bar.
Try This in your java file instead. Will work on runtime but works 100% irrespective of style used.
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setBackgroundDrawable(new
ColorDrawable(ContextCompat.getColor(this, R.color.colorPrimary)));
}
Don't Forget to import required classes and change 'colorPrimary' with color of your choice.
I want to do android program that contains no title bar. For some reason I cant remove title bar.
I have already tried this coding.
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
This one also I have tried but the program suddenly stops..
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
How can I fix this?
In the Style.xml window (App->src->main->res->values->styles.xml)
make changes to the <resources> to look like this:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
</style>
</resources>
This won't work on Android Studio. You need to edit your AndroidManifest.xml and add this line to the Activity in which you want the window title to be removed:
<activity
...
android:theme="#style/Theme.AppCompat.NoActionBar"
...
>
If you require the title to be removed on all activities I suggest to pick a title-less App Theme.
try to change
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
into
this.supportrequestWindowFeature(Window.FEATURE_NO_TITLE);
works for me
Several clean and easy ways to remove the title bar in android application. I have tested them in Android Studio 2.1.1
if MainActivity extends AppCompatActivity in the MainActivity.java,
a. you can add two attributes in the activity tag in the AndroidManifest.xml,
<activity
android:label="#string/app_name"
android:theme="#android:style/Theme.AppCompat.NoActionBar">
...
</activity>
b. or you can add a method in the onCreate() of the MainActivity.java file, before setContentView(R.layout.activity_main);
getSupportActionBar().hide();
if MainActivity extends Activity in the MainActivity.java,
a. you can add two attributes in the activity tag in the AndroidManifest.xml,
<activity
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
...
</activity>
b. or you can add a method in the onCreate() of the MainActivity.java file, before super.onCreate() and setContentView(R.layout.activity_main);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Please mind that you should call this.requestWindowFeature(Window.FEATURE_NO_TITLE) before calling this.setContentView(R.layout.layout_name).
for keeping Last setting Copy This Code (Android studio) res>Values>Styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 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>
if you will need DarTheme Or SomeThing Like That , put Youre Keyword After AppCompact in style tag and in Parent .
Best wishes
I found it better to use "Empty Activity" and put in your app\src\main\res\values\Styles.xml the following config:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
this will give you an app with no title bar and white background.
Add this code style in Style.xml file.
<!-- Base application theme. -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here.-->
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
In the styles.xml file (App/src/main/res/values/styles.xml), make changes to the to look like this:
If you find this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Change it to
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
in AndroidManifest.xml
in application
call this row ==> android:theme="#style/Theme.AppCompat.Light.NoActionBar">
before this row ==> activity android:name=".MainActivity"
I understand that these properties in the manifest:
android:theme="#android:style/Theme.NoTitleBar"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
can remove the title bar.
However, I constantly check the Graphical Layout when I am modifying my app. When I look at the Graphical Layout I still see the title bar. I want to remove the title bar in a way that I don't have to see it during the development of the game.
Simple way is to put this in your onCreate():
// Java
getSupportActionBar().hide();
// Kotlin
supportActionBar?.hide()
In the Design Tab, click on the AppTheme Button
Choose the option "AppCompat.Light.NoActionBar"
Click OK.
for Title Bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
for fullscreen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Place this after
super.onCreate(savedInstanceState);
but before
setContentView(R.layout.xml);
This worked for me.try this
I was able to do this for Android 2.1 devices and above using an App Compatibility library theme applied to the app element in the manifest:
<application
...
android:theme="#style/AppTheme" />
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.NoActionBar">
...
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>
</style>
Note: You will need to include the com.android.support:appcompat-v7library in your build.gradle file
There are two options I'd like to present:
Change the visibility of the SupportActionBar in JAVA code
Choose another Style in your project's style.xml
1:
Add getSupportActionBar().hide(); to your onCreate method.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
}
2:
Another option is to change the style of your Application. Check out the styles.xml in "app->res->values" and change
<!-- 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>
<!-- 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>
Just use this
getSupportActionBar().hide();
If you use AppCompat v7, v21
getSupportActionBar().setDisplayShowTitleEnabled(false);
Use this to remove title from android app in your Androidmainfest.xml
android:theme="#android:style/Theme.NoTitleBar"
or you can use this in your activity
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
If you have import android.support.v7.app.ActionBarActivity; and your class extends ActionBarActivity then use this in your OnCreate:
android.support.v7.app.ActionBar AB=getSupportActionBar();
AB.hide();
In the graphical editor, make sure you have chosen your theme at the top.
It's obvious, but the App Theme selection in design is just for display a draft during layout edition, is not related to real app looking in cell phone.
Just change the manifest file (AndroidManifest.xml) is not enough because the style need to be predefined is styles.xml. Also is useless change the layout files.
All proposed solution in Java or Kotlin has failed for me. Some of them crash the app. And if one never (like me) uses the title bar in app, the static solution is cleaner.
For me the only solution that works in 2019 (Android Studio 3.4.1) is:
in styles.xml (under app/res/values) add the lines:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
After in AndroidManifest.xml (under app/manifests)
Replace
android:theme="#style/AppTheme">
by
android:theme="#style/AppTheme.NoActionBar">
Title bar in android is called Action bar. So if you want to remove it from any specific activity, go to AndroidManifest.xml and add the theme type. Such as android:theme="#style/Theme.AppCompat.Light.NoActionBar".
Example:
<activity
android:name=".SplashActivity"
android:noHistory="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In your res/values/styles.xml of modern Android Studio projects (2019/2020) you should be able to change the default parent theme
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
I went one step further and had it look like this
<!-- 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:windowFullscreen">true</item>
</style>
This is based on the code generated from the Microsoft PWA builder https://www.pwabuilder.com/
in the graphical layout, you can choose the theme on the toolbar. (the one that looks like a star).
choose the NoTitleBar and have fun.
Just change the theme in the design view of your activity to NoActionBar like the one here
Use this Remove title and image from top.
Before:
setContentView(R.layout.actii);
Write this code:
requestWindowFeature(Window.FEATURE_NO_TITLE);
To open the Design window:
res->layouts->activity_manifest.xml
then click on the "Design" button, next to "Code" and "Split". On the TOP LEFT Corner.
Go to res/values/themes and change the third line to .NoActionBar like this in both.
<!-- Base application theme. -->
<style name="Theme.yourApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">