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>
Related
What's wrong with AppCompat?
My application does not use AppCompat and there are no problems with XML Layout
But after I use AppCompat why is the XML Layout not full on the screen?
I tried by creating a new XML layout, but the results were the same.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Hello World!"/>
</LinearLayout>
Add this theme to your activity
in style.xml
<style name="AppTheme" parent="#style/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>
and define this style to your activity in AndroidManifest :
<activity
android:name=".YourActivity"
android:theme="#style/AppTheme"/>
Using this will remove the extra space coming for toolbar by default.
You can achieve fullscreen mode when you use AppCompact like this
Add this to your style file
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen"
parent="#style/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>
And in your manifest file add this to your Activity tag
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen"
I am trying to remove the action bar from an activity.
I have done following but its still keeping the Action bar on my Activity
public class MyActivity extends AppCompatActivity{ .. }
Layout
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context=".TM.TMActivity"
style="#style/AppTheme.NoActionBar"
>
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="#style/AppTheme.NoActionBar"
/>
</android.support.design.widget.CoordinatorLayout>
Style.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Use Theme.AppCompat.Light.NoActionBar its working for me
e.g
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
In styles.xml in values folder,
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
In your activity You can disable.
Check if the correct style has mentioned in the manifest file.
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
And in your style file:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
Check your build.gradle(app) also for dependency.
compile 'com.android.support:appcompat-v7:x.x.x'
There is no need to mention style in Coordinator/Frame layout. Remove the following line from all the layout and try.
style="#style/AppTheme.NoActionBar"
For information, I am using Android Studio 2.0 Preview 7, API 23.
Activity that is having the issue
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="in.ezyride.blovia.OfferRide"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
android:id="#+id/view">
<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" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/view">
<include
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/basicLayoutAddl"
layout="#layout/content_offer_ride"
/>
</ScrollView>
</RelativeLayout>
But other activities are regular. This happened when I was trying to fix the keyboard covering EditText issue. However I almost solved that, new one raised.
For fixing it, I added scroll view in the above relative layout.
The manifest part of the activity is as follows
<activity
android:name=".OfferRide"
android:label="#string/title_activity_offer_ride"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateAlwaysVisible"
android:theme="#style/AppTheme.NoActionBar" />
Other activity where things are normal.
File: styles.xml
<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>
<item name="md_positive_color">#color/colorPrimary</item>
<item name="md_neutral_color">#color/colorPrimary</item>
<item name="md_title_color">#color/colorPrimary</item>
<item name="md_negative_color">#color/colorPrimary</item>
<item name="md_widget_color">#color/colorPrimary</item>
</style>
<style name="FullscreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
<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>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
In my case, the problem was because I had two files styles.xml in my project, in both of them had the same name of theme for the activities.
Let me describe it.
This is my activity in the AndroidManifest.xml:
This is my first styles.xml (default):
This is my second styles.xml (V21):
The app in running mode used the second style, it had the problem, because we couldn't see the colorPrimaryDark of the app.
The solution was, comment the last item in the second style.xml:
http://developer.android.com/reference/android/support/design/widget/AppBarLayout.html
AppBarLayout is a vertical LinearLayout which implements many of the
features of material designs app bar concept, namely scrolling
gestures.
Children should provide their desired scrolling behavior through
setScrollFlags(int) and the associated layout xml attribute:
app:layout_scrollFlags.
This view depends heavily on being used as a direct child within a
CoordinatorLayout
Use CoordinatorLayout instead of RelativeLayout and instead of ScrollView, Use NestedScrollView.
And change this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
Since you already have Toolbar, let's imagine you've already added this in your OnCreate:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
For me, the issue was windowTranslucentStatus:
Before:
<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:colorPrimary">#color/bright_purple</item>
<item name="android:colorPrimaryDark">#android:color/background_dark</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
After:
<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:colorPrimary">#color/bright_purple</item>
<item name="android:colorPrimaryDark">#android:color/background_dark</item>
</style>
Use this in your styles.xml:
<item name="android:statusBarColor">#color/colorPrimaryDarkBlue</item>
I'm having this issue when I applied the toolbar into my app and it crashed when I try to run the app.I used all previous post but no luck.
Here is my code :
Style.xml
<style name="ToolBarStyle" parent="#style/Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
I tried parent="#style/Theme.AppCompat.Light.NoActionBar" but not worked.
Toolbar.xmal
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ToolBarStyle" />
Manifest.axml
<application android:label="Capzure" android:theme="#style/ToolBarStyle" android:icon="#drawable/Icon"></application>
Thank you.
Your theme should look like this, and remove #style/:
<style name="MyMaterialTheme" parent="Theme.AppCompat.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
...
</style>
Then, do not define the theme in <application/> tag. Define it only with activity you want to use the material design theme, i.e. in <activity> tag.
If your activity extends PreferenceActivity, AppCompatActivity, or ActionBarActivity, which you want to begin the transaction with PreferenceFragment, change your theme to:
<style name="MyMaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">true</item>
...
</style>
And remove this line from your Toolbar:
android:theme="#style/ToolBarStyle"
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!