I'm trying to disable the action bar for some of my activities, but no matter what I try I can't seem to remove it.
In my styles.xml I have:
<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>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
And in my manifest.xml I have:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".NewActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
</activity>
</application>
My activity layout file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_new"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
My app_bar_new layout file:
<?xml version="1.0" encoding="utf-8"?>
<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="net.binarysea.sensorload.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<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>
<include layout="#layout/content_new" />
</android.support.design.widget.CoordinatorLayout>
I want the action bar to display on activities apart from one (NewActivity). I use intents to call up NewActivity, at which point I thought it would load up the AppTheme.NoActionBar style, but the bar still appears on the screen
I'm using the navigation drawer activity in android studio if that makes a difference
EDIT: I've tried all the suggesting adding Adding Theme.AppCompat.Light.NoActionBar, but that only makes my action bar white and doesn't actually remove it. I tested this in a new android studio project, created a navigation drawer activity, and add the theme setting to my styles.xml. I still get the same problem
Try this...
Just add parent tag for your style.
Styles.xml
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
AndroidManifest.xml
.......
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".NewActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
</activity>
</application>
........
Try and drop the following into your manifest
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
Follow this Link- https://developer.android.com/training/system-ui/status
Hide the Status Bar on Android 4.1 and Higher-Kotlin
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
supportActionBar?.hide()
Better use it inside onResume().
Another Solution
https://stackoverflow.com/a/28125711/14366835
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
getSupportActionBar().hide(); // hide the title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen
setContentView(R.layout.activity_main);
}}
Use like this in styles.xml
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#color/drawer_bg</item>
</style>
Create seperate layout for toolbar
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</android.support.v7.widget.Toolbar>
In any activity, access this toolbar by using below code.
Toolbar toolbar; //declaration
In onCreate() after setContentView() use this
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
You can try this in your onCreate() of NewActivity to hide the action bar for particular Activity
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
Related
I am using this theme in my Android app, Theme.AppCompat.Light.NoActionBar in every activity my project name i.e the label name from the Application tag appears in every Android activity, before it was not happening but recently it is happening. If I remove the label then the package name appears instead of the title.
What exactly is happening ?
I know that there are several ways to fix it but show me where I am wrong and what is happening ? Is it a bug ?
I referred a previous answer Android Application Name Appears as Activity Name and tried but still did not work, So here is a copy of my manifest.xml
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity2"></activity>
</application>
Below is a sample screenshot, the label name can be seen although that activity(Activity2) consists of a toolbar , the white area is a edittext in the toolbar and nothing else is present inside the toolbar.
EDIT 1
<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:textColor">#color/white</item>
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
</style>
EDIT 2
public class Activity2 extends AppCompatActivity {
LinedEditText editText;
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
toolbar = (Toolbar) findViewById(R.id.toolbar);
editText = (LinedEditText) findViewById(R.id.editText);
setSupportActionBar(toolbar);
}
}
activity2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/green"
android:id="#+id/toolbar"
>
<EditText
android:layout_width="250dp"
android:layout_height="40dp"
android:id="#+id/title"
android:background="#color/white"
android:layout_margin="10dp"
/>
</android.support.v7.widget.Toolbar>
<com.test.testproject.LinedEditText
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/editText"
android:gravity="top"
/>
</LinearLayout>
Check this out.
getSupportActionBar().setDisplayShowTitleEnabled(false);
Check with setting theme for specific activity..which solves your problem..try this
<style name = "NoActionBar" parent = "#android:style/Theme.Holo.Light">
<item name = "android:windowActionBar">false</item>
<item name = "android:windowNoTitle">true</item>
</style>
Just put in onCreate() method after setSupportActionBar(toolbar).
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
actionBar.setTitle("");
UPDATE:
This is your problem. Avoid using Toolbar.
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/green"
android:id="#+id/toolbar"
>
<EditText
android:layout_width="250dp"
android:layout_height="40dp"
android:id="#+id/title"
android:background="#color/white"
android:layout_margin="10dp"
/>
</android.support.v7.widget.Toolbar>
If you are using NoActionBar in your theme. Avoid using Toolbar in your Activity's layout. That is the reason you are getting the Activity name.
If you are using Toolbar make sure you disable the TITLE on it.
When I launch the apps in Emulator, I realize the Navigation bar which shows apps name is missing. May I know what's going on?
public class MainActivity extends Activity implements OnClickListener {
EditText first_name;
EditText last_name;
Button button_submit;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
first_name = (EditText) findViewById(R.id.first_name);
last_name = (EditText) findViewById(R.id.last_name);
button_submit = (Button) findViewById(R.id.button_submit);
button_submit.setOnClickListener(this);
}
#Override
public void onClick(View v) {
Intent intent = new Intent(this, ViewActivity.class);
intent.putExtra("first_name", first_name.getText().toString());
intent.putExtra("last_name", last_name.getText().toString());
startActivity(intent);
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yuqk.intent_usage">
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ViewActivity"></activity>
</application>
Style.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>
</style>
Please refer the the screenshot for reference.. Thanks!
Probably you have
android:theme="#style/AppTheme.NoActionBar"
in your AndroidManifest.xml. If so, you need to change it to
android:theme="#style/AppTheme"
(assuming you have AppTheme defined in styles.xml with parent parent="Theme.AppCompat.Light.DarkActionBar" or similar).
Check this if you add toolbar in xml file like this
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<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>
then add this code to your MainActivity.java file.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
and in Manifest.xml you have use this theme.
android:theme="#style/AppTheme.NoActionBar"
styles.xml you have this
<!-- 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>
If you have toolbar included in your xml, add this line of code inside of onCreate() method, right after setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
There is an option in the Layout editor named 'Show layout decorations'
You must have this option turned off.
There is a button with the image of an eye above the mobile screen in android studio. Click on that and a drop down menu should be seen. Check the 'Show Layout Decorations' and your problem should be solved.
It might that you have changed Style.xml file with theme style of NoActionBar
please change it to
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
and then Run
I have my style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light">
<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" />
and my color.xml:
<color name="colorPrimary">#FC7E0D</color>
<color name="colorPrimaryDark">#E07514</color>
<color name="colorAccent">#EF4B07</color>
It's my overview
I want to make my label white color, but how? I know about TaskDescription, but in this case taskdescription does not help me.
My manifest.xml:
<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.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.class:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.getMenu().performIdentifierAction(R.id.nav_main, 0);
}
...other code...
MainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<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>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="#+id/container_body"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
If you are using tooldbar than you can change color from your activity. and style also but i would suggest you to change it from activity.
In below Code ToolBar id is ab_tool you can give it whatever in your xml
Keep below code in your Activity.
Toolbar toolbar = (Toolbar) findViewById(R.id.ab_tool);
setSupportActionBar(toolbar);
toolbar.setTitleTextColor(Color.WHITE);
If ActionBar is without Toolbar than need to change ActionBar TextView Text color
int titleTextViewResourceID = getResources().getIdentifier("action_bar_title", "id", "android");
TextView txtActionBarTitle = (TextView) findViewById(titleTextViewResourceID);
txtActionBarTitle.setTextColor(Color.WHITE);
Update
AFAIK that is default behavior which is displaying on most recent app.
Title Color is taking by default from internally based on colorPrimary given in style for actionbar or toolbar
System will give title color internally based on colorPrimary.
System will put ActionBar with close button & application icon in most recent apps thumbnail even in your app you are not using ActionBar , toolbar style anything.
Case 1
Here if you give dark color Reddish color(Red scale is more) which you gave in question than it will take Black color as a title color in most recent app even if you give White Color to the title text from xml or runtime in activity.
Sample Image
<color name="colorPrimary">#FC7E0D</color>
<color name="colorPrimaryDark">#E07514</color>
<color name="colorAccent">#EF4B07</color>
<style name="AppThemeSliderToolbar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/slider_bg_primary</item>
<item name="colorPrimaryDark">#color/slider_bg_primary_dark</item>
</style>
Case 2
If you give light color to colorPrimary than system will take black color internally.
<style name="AppThemeSliderToolbar" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/my_primary_light</item>
<item name="colorPrimaryDark">#color/slider_bg_primary_dark</item>
</style>
<color name="slider_bg_primary_dark">#FF5722</color>
<color name="my_primary_light">#B3E5FC</color>
Sample Image case2
How can you change that to White Color
Use below color combination to get white color on most recent app actionbar.
<color name="slider_bg_primary">#ff5b45</color>
<color name="slider_bg_primary_dark">#FF5722</color>
<style name="AppThemeSliderToolbar" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/slider_bg_primary</item>
<item name="colorPrimaryDark">#color/slider_bg_primary_dark</item>
</style>
Used AppThemeSliderToolbar theme in manifest for activity for above all case
White Color TItle
i want to add material drawer in android app ...so we need we have to include a toolbar ..
but when we include toolbar i got error
my Code for activitymain_xml is
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_parent_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true">
<include layout="#layout/toolbar"/>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- The navigation drawer -->
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#004869"
android:textSize="20sp"
android:dividerHeight="1dp"
android:background="#fff"
android:textColor="#f9f5f5"
android:paddingLeft="15sp"
android:paddingRight="15sp"
android:paddingTop="10dp"
/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
code for toolbar is
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
app:theme="#style/ThemeOverlay.AppCompat.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="#drawable/toolbar_background"/>
code for include toolbar is
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
My Style.xml is
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
My Mainifiest file is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lifegoal.eshop"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.lifegoal.eshop.Splash_Screen_Activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</manifest>
But I got error like
04-28 12:53:05.632: E/AndroidRuntime(3181): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lifegoal.eshop/com.lifegoal.eshop.Home_Screen_Activity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
04-28 12:53:05.632: E/AndroidRuntime(3181): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
04-28 12:53:05.632: E/AndroidRuntime(3181): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
Guys I Need ur help ..thx in advance
Try changing your style.xml like below It works for me:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
According to developers guide we have to use NoActionBar theme to use toolbar as a action bar.
Also extends your activity with ActionBarActivity.
Edit
Use AppCompatActivity instead of ActionBarActivity, It is deprecated.
Try to do following :-
Remove this line from your toolbar.xml:-
android:id="#+id/toolbar"
And add this line in your activitymain_xml file:-
android:id="#+id/toolbar"
And extend parent theme Theme.AppCompat.Light.NoActionBar
AppCompat does not support the current theme features
Seems like, your style of Theme is wrong.
Your style.xml should contain these lines:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
P.S. : Your Theme should extend Theme.AppCompat.Light.NoActionBar instead of Theme.AppCompat.Light
The used theme for the actionbar is Theme.AppCompat.Light when using Theme.Holo the issue does not exists.
I am using a custom view for the support v7 actionbar:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white" >
</LinearLayout>
And I get the following result :
How do I remove the black line/divider between the layout and the actionbar.
I have tried changing the actionbar style but with not much of a success.
<resources>
<style name="Theme.Styled" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="dividerVertical">#null</item>
<item name="android:background">#null</item>
<item name="android:paddingTop">0dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:showDividers">none</item>
<item name="android:background">#null</item>
<item name="android:divider">#null</item>
<item name="android:dividerHeight">0dp</item>
<item name="android:dividerPadding">0dp</item>
</style>
</resources>
Here is my Activity Source:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.actionbar);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
}
}
This is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbartest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Styled" >
<activity
android:name="com.example.actionbartest.MainActivity"
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're probably looking for the android:windowContentOverlay attribute.
To remove that drop shadow, simply set the value to #null in your theme, like so:
<style name="Theme.Styled" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:windowContentOverlay">#null</item>
</style>
How do I remove the black line/divider between the layout and the actionbar.
I think you are mistaken. There really isn't a divider present. To confirm:
Open the layout file you're using with setContentView(R.layout.activity_main). Whatever the base container is, set its background to the color you use with the ActionBar. For example, let's say that the base container is a LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white" > <<<====== Add this
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</LinearLayout>
You'll see that the ActionBar now blends with the activity's view.
What you are currently seeing is a gradient defined as:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#ffe8e8e8"
android:endColor="#ffffffff"
android:angle="270" />
</shape>
Here's where the background comes from:
(taken from platforms/android-17/data/res/values/themes.xml)
<style name="Theme.Light">
<item name="windowBackground">#android:drawable/screen_background_selector_light</item>
....
To get rid of it, you can either give your base container a background color, or override this attribute's value in your project's res/values/themes.xml:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">#android:color/white</item>
</style>
Edit:
This is the project setup:
res/layout/activity_main.xml:
<RelativeLayout 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"
android:background="#android:color/white"
tools:context=".MainActivityCompat" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
res/values/styles.xml
<resources>
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
AndroidManifest.xml:
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.trialcompat.MainActivityCompat"
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>
MainActivityCompat.java:
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
public class MainActivityCompat extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.actionbar);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
}
}
R.layout.actionbar is the same as the one you have posted in the question. And this is the result:
As you can see, I cannot reproduce the divider issue. Am I missing something here?
Beside #Vikram answer, add this to the theme:
<item name="android:windowContentOverlay">#android:color/white</item>
Recommendation: Use the same color you use on your layouts. For the default one, use #null
Hope this helps.
I had the same issue. After lots of trials and fails I found that the bug was because of the 9patch background of the action bar.
I switched the 9patch with a regular image and the black line was gone.
For api version >= 21
AppBarLayout appBarLayout = findViewById(R.id.app_bar_layout);
appBarLayout.setOutlineProvider(null);