If I apply theme for whole application it hides ActionBar title successfully:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:displayOptions">showHome|useLogo</item>
</style>
</resources>
assign in manifest:
<application
android:name="myapp"
android:allowBackup="true"
android:icon="#drawable/action_bar_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
I need ActionBar title hidden just in one activity.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
...other things...
</style>
<style name="MainActivityTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:displayOptions">showHome|useLogo</item>
</style>
</resources>
setting this theme explicitly for one activity:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="#+id/mainLayout"
android:orientation="vertical"
android:theme="#style/MainActivityTheme">
and it still shows title in MainActivity ActionBar. I know how to hide the title in java, I need to know what I do wrong here in XML.
Set the theme on your activity in the manifest.
<activity
android:name=".MyActivity"
android:theme="#style/MainActivityTheme" />
You probably want to create a sub-theme which hides the action bar:
<style name="AppTheme.NoActionBar">
<item name="android:windowActionBar">false</item>
</style>
and then apply it to your activity in the manifest like so:
<activity android:name="NonActionBarActivity"
android:theme="#style/AppTheme.NoActionBar" />
Using the dot notation (AppTheme.NoActionBar) makes this NoActionBar theme inherit everything from AppTheme and override the setting on android:windowActionBar. If you prefer you can explicitly note the parent:
<style name="AppThemeWithoutActionBar" parent="AppTheme">
<item name="android:windowActionBar">false</item>
</style>
Also, if you're using the AppCompat libraries, you probably want to add a namespace-less version to the sub-theme.
<item name="windowActionBar">false</item>
If you want to remove actionbar title then just remove label attribute from <activity> tag in your manifest file.
Such as,
<activity
android:name=".YourActivityName"
android:label="#string/title" />
And after removing,
<activity
android:name=".YourActivityName" />
Done!
Related
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 am currently developing my first app in android studio and i am facing a problem that i tried to fix for a while now.
I am trying to remove the first action bar.
I tried changing the theme to a .noActionBar one but to result
Please check out the image for a visual explanation
this is my XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.user.survay_1.SecondActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_red_light"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="#+id/toolbar2"
android:background="#00a4f9"
android:visibility="visible">
</android.support.v7.widget.RecyclerView>
change your theme NoActionBar at styles.xml
<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>
also add
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
write below code in Style.xml:
<style name="LoginTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
</style>
Now u call this theme in manifest.xml with adding this line android:theme="#style/LoginTheme"
See manifest.xml look like :
<activity
android:name=".MainActivity"
android:theme="#style/LoginTheme"
android:windowSoftInputMode="stateHidden" />
getSupportActionBar().hide();
In your Activity just use this :- only one line
You can do it in two ways.
First way is to disable it in styles.xml file:
styles.xml
<style name="CustomTheme.NoActionBar" parent="CustomTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
And in your AndroidManifest.xml you can use it for all activities:
<application android:theme="#style/CustomTheme.NoActionBar">
Or for one activity only:
<activity android:theme="#style/CustomTheme.NoActionBar">
The second way is to hide action bar from your activity:
Activity.class
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
declare custom theme in your style.xml file like this..
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
</style>
then in your manifest give your activity theme like this..
<activity android:name=".ActivityName"
android:theme="#style/AppThemeNoActionBar">
</activity>
i would like to remove title bar on applications blue bar in android studio,i've tried using a different theme in manifest.xml
( android:theme="#style/AppTheme.NoTitleBar") but this didn't work, then, how i do to hide this title bar from this activity?
my manifest.xml is this:
and my styles.xml is this:
On the left side above the phone( layout preview ) there AppTheme text click on that and choose the theme that you want. I've highlighted it with red
Go to App>Res>Values>styles xml.
The first thing that you have after the <resources> tag is another <style> tag with the name AppTheme probably? Or something similar. If you're using a Material theme, you'd have the colorPrimary, colorPrimaryDark and accentColor declared there.
After the end of the </style> tag for this theme, create a new one with the same name but add .NoActionBar to the name, like that:
<style name="YourThemeName.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
Now go to your Manifest.xml and in each <activity> tag there probably is a theme attribute. Change it so that the activity you want to not have a title bar uses the new theme we created:
android:theme="#style/YourThemeName.NoActionBar"
How your theme should look like:
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/teal</item>
<item name="colorPrimaryDark">#color/tealDark</item>
<item name="colorAccent">#color/purple700</item>
<item name="android:navigationBarColor" tools:targetApi="21">#color/teal</item>
</style>
<style name="MyTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
Just remember to change the color names to the ones you have declared in your colors.xml . Now in your Manifest, the Theme for your app should be MyTheme and the theme for each Activity not using a Title bar should be MyTheme.NoActionBar
this is my Stiles.xml
<resources>>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<style name="AppTheme.NoTitleBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
and for my activity manifest.xml i do this:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Main2Activity"
android:label="#string/title_activity_main2"
android:theme="#style/AppTheme.NoActionBar" />
</application>
I am assuming you are using the latest version of Android for your app. If not please mention the version of Android that is being used. Following is the way in which you can remove the blue bar on the top of the activity:-
Go to the activity xml file and remove the following code from the xml:-
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
Now if you switch to the design mode then you will be able to see the screen without the blue bar on the top.
Hope this helps.
I'm trying to make a custom theme for my android app. But the problem is that I can't change actionbar theme. When the style is applied, it gave me the following error and shutdown the app:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I can't understand what I'm doing wrong. Here's my code:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.liderlink.dev.acelink" >
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AcelinkTheme">
<activity
android:name=".Dashboard"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light">
<!-- Customize your theme here. -->
</style>
</resources>
res/values/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="AcelinkTheme"
parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/AcelinkActionBar</item>
</style>
<!-- colors -->
<color name="aceblue">#438eb9</color>
<!-- ActionBar styles -->
<style name="AcelinkActionBar"
parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/aceblue</item>
</style>
</resources>
The exception is pretty clear : you need to use a theme that inherits from Theme.AppCompat, probably because you are using ActionBarActivity, which requires it as specified in the docs.
You can do this :
<style name="AcelinkTheme" parent="#android:style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/AcelinkActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="AcelinkActionBar" parent="#android:style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/aceblue</item>
</style>
For clarity, it is better to have colors defined in their own resource file IMHO.
According to this thread, you should change your parent to a Theme.AppCompat theme derivate:
<style name="AcelinkTheme"
parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/AcelinkActionBar</item>
</style>
This link should also help you to customize your theme: Styling the Action Bar :)
I'm a beginner in Android development and I trying to build my theme but I have a problem. I tried searching answers on google, d.android but to no avail.
ActionBar is changing color (this is OK), but text and icon of app doesn't show (only if I use my theme - if I use default theme everything is OK). Why?
res/values/styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="AppTheme">
<item name="android:background">HEX COLOR</item>
<item name="android:titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="AppTheme">
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>
Here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.appname"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.appname.Intro"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
"You should add following code in onCreate() method.
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher); "
I see the problem that you use AppTheme as parent for MyActionBar style and it causes circular dependency. MyActionBar -> AppTheme -> MyActionBar ... You should use android:Widget.ActionBar or similar as parent of your action bar theme.
Also there should be android:Theme.Holo.Light instead of android:Theme.Light as parent of AppBaseTheme.
Here is how your res/values/styles.xml file should look like:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Holo.Light"/>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:Widget.ActionBar">
<item name="android:background">HEX COLOR</item>
<item name="android:titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="AppTheme">
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>