Theme.AppCompat.Light.DarkActionBar is not showing Action bar - android

I am trying to add materiel design in my project. Whan I try to apply new theme I am facing some problem. Action bar is hided when I apply this theme to my activity.
Style:
<style name="MaterialBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/GreenActionBar</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView</item>
<item name="android:textAppearanceLargePopupMenu">#style/PopupMenuTextAppearance</item>
</style>
Manifest:
<activity
android:name=".Summary"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/summary"
android:launchMode="singleTop"
android:theme="#style/MaterialBaseTheme"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden" />
Class:
public class Summary extends BaseActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.route_summary);
super.onCreate(savedInstanceState);
// parseView();
// updateUI();
}
}
Here Action bar is hided for this activity.
When I try to extend AppCompatActivity in class I am getting flowing error.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.coc.Summary}:
java.lang.IllegalArgumentException: AppCompat does not support the current theme features
Please let me any idea to resolve my problem.

Please add other styles for theme
<style name="MaterialBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/**GreenActionBar**</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:popupMenuStyle">#style/**PopupMenu**</item>
<item name="android:dropDownListViewStyle">#style/**DropDownListView**</item>
<item name="android:textAppearanceLargePopupMenu">#style/**PopupMenuTextAppearance**</item>
</style>
use this
public class MainActivity extends AppCompatActivity

Related

White space when Actionbar is hidden in OS versions higher than 6.0?

I created a new android project in Android 6.0. In activity, I do getSupportActionbar().hide() (in OnCreate()). Actionbar was hidden, but white space is showing? Please help me this problem. Thanks!!
This is best & easy way to hide default action bar from android activity.
Put these two styles in res>values>styles.xml. You may already have AppTheme
<!-- 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" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and in your manifest class
<activity
android:name=".YourActivityName"
android:theme="#style/AppTheme.NoActionBar">
</activity>
package com.example.administrator.myapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
}
}

How to have a new activity start with the action bar not visible using a theme?

Why doesn't this style I have result in the action bar not being displayed?
My activity is descended from appcompat. I assume these are all the correct properties.
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="Theme.AppCompat.Light">
<item name="android:windowFullscreen">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
it is taking effect, cause the status bar gets removed. But the action bar doesn't seem to get affected.
I can still successfully remove the action bar like this:
public class MainMenuScreen extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main_menu_screen);
but i have to admit I'm a little bit disappointed that I can't do it from xaml.
Can you show your manifest? Where do you associate the theme with the activity?
Try something like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="BaseTheme" />
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/cobalt_light</item>
<item name="colorPrimaryDark">#color/cobalt</item>
<item name="colorControlHighlight">#color/cobalt_lighter</item>
<item name="colorAccent">#color/cobalt_light</item>
</style>
</resources>
You dont need to extends from parent Theme.AppCompat.Light

getSupportActionBar() returns null after changing theme

I open activity with transparent style, it means that it has this theme at the start:
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
After few moments I change theme
setTheme(R.style.AppThemeWithActionBar);
which looks like this:
<style name="AppThemeWithActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">false</item>
<item name="android:windowNoTitle">false</item>
<item name="android:windowIsTranslucent">false</item>
<item name="colorPrimary">#color/primaryDark</item>
<item name="colorPrimaryDark">#color/primary</item>
<item name="colorAccent">#color/accent</item>
</style>
But unfortunately, when I call getSupportActionBar() after changing theme I get null, what is the reason?
There are two ways to set a style:
Using AndroidManifest.xml
for Entire Application :
<application android:theme="#style/CustomTheme" >
</application>
for Individual Activity :
<application>
<activity android:theme="#style/CustomTheme" >
...
</activity>
</application>
Programmatically :
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.CustomTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
It's not possible to change theme at runtime without reloading whole activity. Because I don't want to reload activity, I will have to stop using ActionBar and start using Toolbar.

Action bar looks cut while using Theme.AppCompat.Dialog

I wished to make one of my activities to look like a dialog and used a Theme.AppCompat.Dialog theme for it, but it made it's action bar to look bad (see below).
Now background is cut to the length of the title string and I cant't find any theme property to fix it.(
What can be done to avoid it?
Related part of styles.xml:
<style name="DeviceListTheme" parent="Theme.AppCompat.Dialog">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
I start the activity using the following code:
Intent intent = new Intent(this, DeviceListActivity.class);
startActivityForResult(intent, REQUEST_CONNECT_DEVICE);
First, when I encountered this problem, I tried using supportRequestWindowFeature(Window.FEATURE_NO_TITLE); but this didn't work for me and had no effect.
The alternative method to remove the bar at the top of your dialog activity would be to create a custom style and apply it to that activity.
In styles.xml, create a new style like so:
<style name="MyCustomDialog" parent="Base.Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
Now, in AndroidManifest.xml, add in android:theme="#style/MyCustomDialog" to your activity.
Of course, MyCustomDialog can be renamed to anything you want.
Use DialogWhenLarge instead of standard Dialog style:
<style name="MyDialogTheme" parent="#style/Theme.AppCompat.Light.DialogWhenLarge">
...
</style>
I solved the same problem this way:
Activity:
public class MyActivity extends android.support.v4.app.FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
setTitle("View task");
}
}
Theme:
<style name="Theme.MyDialog" parent="#style/Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">false</item>
</style>
Manifest:
<activity android:name=".MyActivity" android:theme="#style/Theme.MyDialog"/>
Result:
Its Working
<style name="AppThemeDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:spinnerStyle">#style/holoSpinner</item>
</style>
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
setTitle("Batches");
}

Android how to get AppCompat.Translucent type theme with support actionbar?

I would like to add the support actionbar to one of my activities, I previously had been using the theme.translucent with this activity but in order to make the support actionbar work I needed to inherit the Theme.AppCompat, I need to maintain a translucent theme in this activity but unfortunately there isnt a Theme.AppCompat.translucent that i can see by default, is there any way that this can be done?
You can create a new set of styles to use which have the same properties as Theme.Translucent from themes.xml.
Add the following to your styles.xml file:
<style name="Theme.AppCompat.Translucent">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
</style>
You can change the prefix Theme.AppCompat to something else if you want to inherit other things from the theme such as dialog styles etc. For example, a name like Theme.AppCompat.Light.Translucent would have the properties of the Light theme.
To use the new style, set the theme property to #style/Theme.AppCompat.Translucent
<activity
android:name=".TranslucentActivity"
android:theme="#style/Theme.AppCompat.Translucent" >
</activity>
Parama ,
<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
</style>
This should be the style header if you want the toolbar to disappear.you can use any parent theme which has NoActionBar for other effects.
Hope this helps
If we use Translucent for transparent activity.
It raises other issues - the color of Msgbox (now white previously black), Default dialog color, the spinners do drop down but do not show the underline and drop-down arrow. The spinners are color black text black; drop-down white drop-down text black and etc.
To overcome this problem, you can just use below code
In style
<style name="Theme.AppCompat.Transparent.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
In manifest file
<activity
android:name=".activity.YourActivityName"
android:theme="#style/Theme.AppCompat.Transparent.NoActionBar" />
I hope it will help
Thanks
Cameron's answer is a nice hack , but it produced a floating action bar and tinted my status bar, which i didn't wanted . So i added more xml attributes for making status bar transparent(for sdk >=19) and used java code for making action bar invisible.
mainActivity.java :
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
...
}
...
}
styles.xml
<style name="AppTheme.TranslucentBG">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
manifest.xml
<application
android:icon="#mipmap/ic_launcher"
...
android:theme="#style/AppTheme"
...
>
<activity android:name=".MainActivity"
android:theme="#style/AppTheme.TranslucentBG"
...
>
...
</activity>
</application>

Categories

Resources