I'm slowly moving my app to Android Lollipop, in fact I'm just beginning this process.
But I'm already having some problems. The first one is that I can't make the icon appear in the ActionBar again. Just the app name and buttons appear.
Here is my style:
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">true</item>
<item name="actionBarStyle">#style/MyApp.Widget.ActionBar.Solid</item>
<item name="actionBarTabStyle">#style/MyApp.Widget.ActionBarTabStyle</item>
<item name="actionModeBackground">#drawable/cab_background_top_MyApp</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_MyApp</item>
<item name="actionModeCloseButtonStyle">#style/MyApp.Widget.ActionButton.CloseMode</item>
<item name="actionBarItemBackground">#drawable/selectable_background_MyApp</item>
</style>
<style name="MyApp.Widget.ActionBar.Solid" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:logo">#drawable/ic_launcher</item>
<item name="background">#drawable/actionbar_background</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_MyApp</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_MyApp</item>
<item name="progressBarStyle">#style/MyApp.Widget.ProgressBar</item>
</style>
And here is my AndroidManifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:name=".MyApp"
android:theme="#style/AppTheme" >
<activity
android:name="com.br.myapp.MainActivity"
android:label="#string/explore"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
</activity>
</application>
And my activity class is extending ActionBarActivity from the AppCompat library v21.
Try adding the following two lines in onCreate of your main Activity:
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.your_actionbar_icon);
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
Goal: I want to allow user to change the color theme of my app.
Themes (styles.xml):
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
<item name="android:statusBarColor">#color/indigoColorPrimaryDark</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.FullScreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme.MainActivity">
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<style name="AppTheme.SearchActivity">
<item name="android:statusBarColor">#android:color/darker_gray</item>
<item name="android:windowAnimationStyle">#null</item>
</style>
<!-- Colors -->
<style name="AppTheme.Indigo">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
<item name="android:statusBarColor">#color/indigoColorPrimaryDark</item>
</style>
<style name="AppTheme.Blue">
<item name="colorPrimary">#color/blueColorPrimary</item>
<item name="colorPrimaryDark">#color/blueColorPrimaryDark</item>
<item name="colorAccent">#color/blueColorAccent</item>
<item name="android:statusBarColor">#color/blueColorPrimaryDark</item>
</style>
<style name="AppTheme.Red">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
<item name="android:statusBarColor">#color/redColorPrimaryDark</item>
</style>
<!-- some other colors -->
</resources>
As you can see, I have the main theme AppTheme that as a default color ("indigo").
I have three other themes FullScreen, MainActivity and SearchActivity that derive from AppTheme, and then colors themes.
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.superbstudios.reportnote">
<uses-permission android:name="android.permission.INTERNET" />
<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=".SignInActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.FullScreen" />
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SearchActivity"
android:label=""
android:theme="#style/AppTheme.SearchActivity"
android:windowSoftInputMode="stateVisible" />
<activity
android:name=".SettingsActivity"
android:label="#string/title_activity_settings"
android:theme="#style/AppTheme" />
<activity
android:name=".GuideActivity"
android:label="#string/title_activity_guide"
android:theme="#style/AppTheme" />
</application>
</manifest>
Now, only SignInActiviy, MainActivity and SearchActivity has their own themes, the other activity (also application) has AppTheme.
What I do: I create a BaseActivity class, and all activity extend this class.In BaseActivity in onCreate method before super declaration I use this code to change color theme:
setTheme(R.style.AppTheme_Red);
Problem: This code change the theme for all activity and also for SignInActiviy, MainActivity and SearchActivity that needs a different theme.
I don't know if the colors theme are useful.
The only things i want is to change the AppTheme colors like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
<item name="android:statusBarColor">#color/redColorPrimaryDark</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
So, what I have to do to change colors of my app?
I solved it by changing styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.FullScreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme.MainActivity">
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<style name="AppTheme.SearchActivity">
<item name="android:statusBarColor">#android:color/darker_gray</item>
<item name="android:windowAnimationStyle">#null</item>
</style>
<!-- Colors -->
<style name="Indigo">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
</style>
<style name="Blue">
<item name="colorPrimary">#color/blueColorPrimary</item>
<item name="colorPrimaryDark">#color/blueColorPrimaryDark</item>
<item name="colorAccent">#color/blueColorAccent</item>
</style>
<style name="Red">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
</style>
</resources>
And in my BaseActivity i use this code:
getTheme().applyStyle(R.style.Blue, true);
Referenced to the comment
I'll answer by taking Red color as an example
If you only want to change the colorPrimary then keep only it.
<style name="AppTheme.Red">
<item name="colorPrimary">#color/redColorPrimary</item>
</style>
Other wise create two themes for Red color. One with status bar color and other inheriting that with transparent status bar.
<style name="AppTheme.Red">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
<item name="android:statusBarColor">#color/redColorPrimaryDark</item>
</style>
<style name="AppTheme.RedTransparentStatus" parent="AppTheme.Red>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
So if you want status bar to transparent you can set the second theme or else the first.
From my understanding, you want to keep the default "Indigo" color for
SignInActivity, MainActivity, SearchActivity.
Todo so inherit the relevant themes of those activities with AppTheme
<style name="AppTheme.SearchActivity" parent="AppTheme">
...
</style>
I have tried lots of to make activity or main layout transparent using theme defined into style.xml with different different attribute in theme still not working.
Only view.setalpha(0) that makes layout or activity is transparent, but how to possible through style.xml. I am using Theme.AppCompact for support lower version of Android device.
Also i have tried lots of SO answer but none of one is working. What i am doing wrong or any correction there? what I have done so far is as following.
Please help me to solve the issue.
style.xml
<!-- Base application theme. -->
<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>
<style name="Theme.AppCompat.Translucent" parent="AppTheme">
<item name="android:background">#android:color/transparent</item> <!-- Or any transparency or color you need -->
<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:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
</style>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="demo.intel.com.serviceprogressbarnotification">
<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"
android:theme="#style/Theme.AppCompat.Translucent">
</activity>
<activity android:name=".TestActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Well I have same case but I wanted to make my window to act like dialog and on the background of it I put my required transparency level. here is the style I used:
<style name="transparent_alertDialog" parent="Theme.AppCompat.Dialog.Alert">
<item name="windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:backgroundDimAmount">0.95</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowMinWidthMajor">50%</item>
<item name="android:windowMinWidthMinor">50%</item>
<item name="android:windowContentOverlay">#null</item>
<item
name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowCloseOnTouchOutside">false</item>
</style>
and in manifest I used it like :
<activity
android:name=".PaymentConfirmationActivity"
android:label=""
android:theme="#style/transparent_alertDialog"
android:windowSoftInputMode="adjustPan"/>
So it did the trick for me.
Hope so it will help for you too.
I have changed actionbar color and other things to open in required color and text but when I open the app: The app opens with default theme and immediately changes to given theme.
This happens in phones like Galaxy Nexus, Nexus 4 but not on Nexus 5. I am not sure why this is happening?
I have set the actionbar before setContentView in my APP
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(true);
getActionBar().setIcon(android.R.color.transparent);
getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionBarColor)));
setContentView(R.layout.activity_main);
}
I got the theme using: http://jgilfelt.github.io/android-actionbarstylegenerator/
My style which I got from the above looks like this:
<style name="Theme.link" parent="#android:style/Theme.Holo">
<item name="android:actionOverflowButtonStyle">#style/ThemeFor.OverFlow</item>
<item name="android:actionBarItemBackground">#drawable/selectable_background_link</item>
<item name="android:popupMenuStyle">#style/PopupMenu.link</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.link</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.link</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.link</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.link</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_link</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_link</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.link</item>
</style>
<style name="ActionBar.Solid.link" parent="#android:style/Widget.Holo.ActionBar.Solid">
<item name="android:background">#drawable/ab_background_textured</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_link</item>
<item name="android:backgroundSplit">#drawable/ab_background_textured_link</item>
<item name="android:progressBarStyle">#style/ProgressBar.link</item>
</style>
<style name="ActionBar.Transparent.link" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/ab_transparent_link</item>
<item name="android:progressBarStyle">#style/ProgressBar.link</item>
</style>
<style name="PopupMenu.link" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_link</item>
</style>
<style name="DropDownListView.link" parent="#android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_link</item>
</style>
<style name="ActionBarTabStyle.link" parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_link</item>
</style>
<style name="DropDownNav.link" parent="#android:style/Widget.Holo.Spinner">
<item name="android:background">#drawable/spinner_background_ab_link</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_link</item>
<item name="android:dropDownSelector">#drawable/selectable_background_link</item>
</style>
<style name="ProgressBar.link" parent="#android:style/Widget.Holo.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_link</item>
</style>
<style name="ActionButton.CloseMode.link" parent="#android:style/Widget.Holo.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_link</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.link.Widget" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu.link</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.link</item>
</style>
And I am calling the theme in Manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.link" >
<activity
android:name=".Link_Main"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Link_Support"
android:label="#string/action_support"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.ylg.linking.Link_Main" />
</activity>
</application>
Can somebody help me fix this?
Thanks!
Try to add <item name="android:actionBarStyle">#style/Theme.link</item> to your base Activity style in AndroidManifest.xml.
I think you should change a value for android:background in ActionBar.Solid.link to #color/actionBarColor.
This is happening because when the application run, it gets style from styles.xml so your default style would be visible to you and after that you are changing actiob bar in onCreate() so theme changes immediately. To solve this set the icon and background color of action bar using styles.xml only using below code.
Try it. Hope it works.
<style name="AppBaseTheme" parent="#android:style/Theme.Holo.Light">
.....
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" arent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/actionBarColor</item>
<item name="android:text">""</item>
<item name="android:icon">#android:color/transparent</item>
</style>
And remove below code.
getActionBar().setIcon(android.R.color.transparent);
getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionBarColor)));
How does one style the Android ActionBar overflow menu (background color, text color, custom drawables etc.)?
I've been trying to do this with the following styles, but nothing seems to be taking any effect. Any help would be greatly appreciated.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarWidgetTheme">#style/MyActionBar</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:textColor">#android:color/holo_blue_light</item>
<item name="android:actionBarItemBackground">#android:color/holo_green_light</item>
<item name="android:actionMenuTextColor">#android:color/holo_green_dark</item>
</style>
</resources>
TIA!
BTW minSdk set to 14
AndroidManifest is
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app1.app1">
<application android:allowBackup="true"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
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>
</application>
</manifest>
Do you call it on AndroidManifest.xml file?
Example in my style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/green_dark</item>
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/white</item>
<item name="android:textStyle">bold</item>
</style>
and in menifestfile
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher1"
android:label="#string/app_name"
android:theme="#style/CustomActionBarTheme" >
<activity.....
For implement click listener, you need create option menu for this case.