I am using AppCompat them from support V7. I am trying to make one screen full screen but with notification bar visible(solid color or transparent).
In styles.xml i have this:
<style name="Theme.MyAppTheme" parent="#style/Theme.AppCompat">
<item name="android:windowActionBarOverlay">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowNoTitle">false</item>
</style>
And in the class, in onCreate() i have this:
super.onCreate(bundle);
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
Still, curious enough, the nativation bar still does not appear on it's own. Is there a property I should be using in the styles to make it correct? Thank you.
Style.xml
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"> </style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
In your manifest.xml
<activity
android:name="YourActivity"
android:theme="#android:style/Theme.Light.NoTitleBar">
</activity>
Related
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" />
I use Lg Q6. Version 7.1.1. Navigation bar color not change with code below. I try to change dynamically and using theme but nothing is change. I dont understand Where Im do something wrong ?
First try programatically
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(getResources().getColor(R.color.your_awesome_color));
}
Then try style.xml
Manifest.xml
<application
android:theme="#style/AppTheme">
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>
<item name="windowNoTitle">true</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:navigationBarColor">#color/black</item>
</style>
Every time you want to change the color of a comment or item in the entire app, it's best to put a special style into it and introduce it to the original style of the program.
For Example : if you want change background of bottom Navigation Bar you can add under lines in style.xml v21 :
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:navigationBarColor">#color/colorAccent</item>
</style>
but if you want change background color of toolbar , you should define an style for it , for example :
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
.
.
.
<item name="toolbarStyle">#style/MyStyle</item>
</style>
<style name="MyStyle" parent="Theme.AppCompat.Light">
<item name="android:background">#024dfc</item>
</style>
you can use this way for define night and day theme for your app .
I hope you enjoyed .
I am trying to give transparent effect to my action bar. I have used the following line to make it work that way, but strangely on my Nexus 5 I am can see the bar coming, but on my galaxy nexus I don't see it at all.
I am not sure why this is coming up on N5? How to solve this issue?
Here is the code:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(false);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
setContentView(R.layout.profile);
Here is the screenshot for both Galaxy nexus running Jelly Bean (4.3) and Nexus 5 running kitkat (4.4.4)
Galaxy Nexus: showing transparent action bar perfectly:
Nexus 5: showing transparent action bar: (A horizontal line is shown)
Update 2:
I managed to remove the line on N5 by using the following style
styles.xml in Values-v14 folder
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"></style>
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo"></style>
then added theme to specific activity in manifext:
<activity
android:name=".Profile"
android:label="#string/profile"
android:theme="#style/CustomActionBarTheme"
android:screenOrientation="portrait" >
but then all my text, dialog format have changed in this activity. It has become dark. It doesn't change even though I programatically change the theme for dialog. I am not sure what is wrong? Can someone help me out with this?
Update 1: As per #erakitn advice: I tried the following with few changes:
<!-- Transparent ActionBar Style -->
<style name="CustomThemeTransparent" parent="AppBaseTheme">
<item name="android:background">#android:color/transparent</item>
<item name="background">#android:color/transparent</item>
</style>
<!-- Activity Theme with transparent ActionBar -->
<style name="CustomThemeTransparentLight" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/CustomThemeTransparent</item>
<item name="actionBarStyle">#style/CustomThemeTransparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
I have getting the following error:
1. error: Error: No resource found that matches the given name: attr 'background'.
2. error: Error: No resource found that matches the given name: attr 'actionBarStyle'.
3. error: Error: No resource found that matches the given name: attr 'windowActionBarOverlay'.
To remove ActionBar shadow try to add <item name="android:windowContentOverlay">#null</item> attribute to your Activity theme. Below there is an example of theme with transparent ActionBar. Define it in res/styles.xml:
<!-- Your App Theme-->
<style name="YourAppTheme.Light" parent="#style/Theme.AppCompat.Light">
<...>
</style>
<!-- Transparent ActionBar Style -->
<style name="YourAppTheme.Light.ActionBar.Transparent" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#android:color/transparent</item>
<item name="background">#android:color/transparent</item>
</style>
<!-- Activity Theme with transparent ActionBar -->
<style name="YourAppTheme.TransparentActionBar.Light" parent="#style/YourAppTheme.Light">
<item name="android:actionBarStyle">#style/YourAppTheme.Light.ActionBar.Transparent</item>
<item name="actionBarStyle">#style/YourAppTheme.Light.ActionBar.Transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
And set this theme to your Activity:
<activity
android:name="your.package.name.YourActivity"
android:label="#string/app_name"
android:theme="#style/YourAppTheme.TransparentActionBar.Light" />
UPD:
If you are not using AppCompat or ABS you should use HOLO theme as parent for your theme. It seems you use light theme with dark ActionBar. Please try following solution:
<!-- Your App Theme-->
<style name="YourAppTheme.Light" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<...>
</style>
<!-- Transparent ActionBar Style -->
<style name="YourAppTheme.Light.ActionBar.Transparent" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#android:color/transparent</item>
</style>
<!-- Activity Theme with transparent ActionBar -->
<style name="YourAppTheme.TransparentActionBar.Light" parent="#style/YourAppTheme.Light">
<item name="android:actionBarStyle">#style/YourAppTheme.Light.ActionBar.Transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
Please don't change anything
Your original code is just fine. All you need to do is set/apply the following attribute:
android:windowContentOverlay = true
Again, don't change your theme/style. Define a new one like this:
<style name="ConOver" > <<== no parent
<item name="android:windowContentOverlay">#null</item>
</style>
Add this above your code:
// Add this line
// Lets you add new attribute values into the current theme
getTheme().applyStyle(R.style.ConOver, true);
// Rest stays the same
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(false);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new
ColorDrawable(android.graphics.Color.TRANSPARENT));
actionBar.setStackedBackgroundDrawable(new
ColorDrawable(android.graphics.Color.TRANSPARENT));
setContentView(R.layout.profile);
Since you are using DarkActionBar as a theme now the dialog will turn black all around because that is the style DarkActionBar is using.
You can style your dialog from default light theme of HOLO for dialogs.
sample:
final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_Holo_Light_Dialog));
EDIT:
Change this:
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo"></style>
To
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light"></style>
I was able to create a floating activity after following this tutorial http://cases.azoft.com/android-tutorial-floating-activity/
However, to do so, I had to add this line in styles.xml :
<item name="android:windowIsTranslucent">true</item>
Is it possible to have the same effect using only Android/Java code ? (e.g. in Activity.onAttachedToWindow() or so...)
Thanks in advance for your help.
[EDIT 01] styles.xml must not be changed (and I'm not supposed to know what's in it...). But for testing purposes, I'm using the default one:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
[EDIT 02] Resources.Theme.applyStyle() seems to do what I want (according to the API description: "Place new attribute values into the theme" ).
So I created the following custom_style.xml :
<resources>
<style name="MyCustomStyle" >
<item name="android:windowIsTranslucent">true</item>
</style>
</resources>
Then, in onAttachedToWindow() , I called:
getTheme().applyStyle(R.style.MyCustomStyle, true);
But it didn't have any effect...
Is it possible to have the same effect using only Android/Java code ?
I am afraid, No. You will have to do it in styles.xml only. AFAIK value of android:windowIsTranslucent alone can't be changed programatically.
When we call super.onCreate(savedInstanceState); the Activity class provides empty graphical window on which we set our content ie.views. And a theme is applied to this window and then the content are loaded on this view.
Hence the sequence will be,
call to super.onCreate()
setting theme for the activty.
seting the content views for that activity.
eg.
styles.xml
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowBackground">#drawable/background</item>
<item name="android:windowNoTitle">true</item>
</style>
<!-- Application theme.without title bar -->
<style name="AppTheme.NoTitleBar" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowBackground">#drawable/background</item>
<item name="android:windowNoTitle">true</item>
</style>
<!--Floating activity theme -->
<style name="Theme_Translucent" parent="android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowFullscreen">true</item>
</style>
Then set your theme for Floating activity as follows:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setTheme(R.style.Theme_Translucent); // Set here
setContentView(...)
}
do this
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window w = getWindow(); // in Activity's onCreate() for instance
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
Can't say about to do this programatically .. but if you need to do this you can give a try like this ..
Add theme to you activity in manifest file like this ..
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
Example :-
<activity
android:name="com.example.androidhackerphonelocker.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Hope it solves some problem of your's ..
Maybe this can help.
#Override
protected void onCreate(Bundle savedInstanceState) {
processSetTheme(this);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setBackgroundDrawableResource(R.color.realTranslucent);
if (Build.VERSION.SDK_INT>=19){
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
super.onCreate(savedInstanceState);
<color name="realTranslucent">#00000000</color>
There a new method appeared in Android R
if android.app.Dialog
window.setDimAmount(0f)
window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
I am trying to change the background of the action bar via xml, but the action bar is not shown anymore at all.
This is the style that I am using, declared in styles.xml:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/DiaryActionBar</item>
<item name="android:actionBarStyle">#style/DiaryActionBar</item>
</style>
<style name="DiaryActionBar"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="background">#color/action_bar_bg</item>
<item name="android:background">#color/action_bar_bg</item>
</style>
I have set both android:background and background for compatibility. This is the only styles.xml file in my app. What am I doing wrong?
In my style with custom actionbar background, i have this:
<style name="Theme.Malaka" parent="#style/Theme.AppCompat">
<style name="Malaka.ActionBar" parent="#style/Widget.AppCompat.ActionBar">
And that works just fine. Items of the styles are the same as yours. Please note that the parent of Malaka.ActionBar is not Theme... but Widget...
For changing background and actionBarStyle from android styling.You can do like this..
<style name="AppBaseTheme" parent="#android:style/Theme.Black">
<item name="android:actionBarStyle">#style/Theme.DeviceDefault.NoActionBar</item>
</style>
<style name="DiaryActionBar" parent="#android:style/Theme.Black">
<item name="android:background">#color/action_bar_bg</item>
</style>