How to use device default theme? If I use this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.DeviceDefault">
</style>
</resources>
it is crashing application. Exception
I don't know if the theming is the issue but to apply themes you will do the following..
add/change in styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat">
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="StyledDialog.Base" parent="Theme.AppCompat.Dialog">
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
create a folder in res called values-v21 and copy the styles.xml into now change there the code to something like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:colorPrimary">#color/primaryColor</item>
<item name="android:colorPrimaryDark">#color/primaryColorDark</item>
<item name="android:colorAccent">#color/colorAccent</item>
</style>
<style name="StyledDialog" parent="Theme.AppCompat.Dialog">
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
In your manifest you will have to call the theme by
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
Now your app will support the default theming of Lollipop and earlier versions of android.
Edit: Don't get confused by the "Dialog"-entries.. I just overwrite them to apply the theming to them with an other style..
Related
I am getting below error while importing the eclipse code to Android studio.
I am not getting why this is happening
I have already tried for possible solutions by checking XMLNS and other custom tags.
Remove all xmlns:android="http://schemas.android.com/apk/res/android" in your main\res\values\style.xml file from style tag.
Here is is the sample code:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
<style xmlns:android="http://schemas.android.com/apk/res/android" name="RadioButton" parent="#android:style/Widget.CompoundButton">
<item name="android:button">#null</item>
<item name="android:padding">5dp</item>
</style>
<style xmlns:android="http://schemas.android.com/apk/res/android" name="EditText" parent="#android:style/Widget.EditText">
<item name="android:textSize">15sp</item>
</style>
</resources>
It should be like this:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
<style name="RadioButton" parent="#android:style/Widget.CompoundButton">
<item name="android:button">#null</item>
<item name="android:padding">5dp</item>
</style>
<style name="EditText" parent="#android:style/Widget.EditText">
<item name="android:textSize">15sp</item>
</style>
</resources>
I'm trying to change the background color of my Actionbar, but after referencing the several other questions on this site I still can't get their solutions to work.
Styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/ActionBar</item>
<item name="android:windowActionBar">true</item>
</style>
<style name="ActionBar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="background">#color/light_blue_menu_bar</item>
</style>
</resources>
colors.xml
<resources>
...
<color name="blue_semi_transparent_pressed">#80738ffe</color>
<color name="light_blue_menu_bar">#87CEFA</color>
</resources>
manifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
However the ActionBar doesn't appear in of my views. What am I missing?
EDIT
The solution was to add to styles.xml
<item name="android:windowActionBar">true</item>
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
<item name="actionBarStyle">#style/ActionBarStyle</item>
<item name="android:windowActionBar">true</item>
</style>
<style name="ActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="background">#color/blue</item>
<item name="android:background">#color/blue</item>
</style>
You can use this,
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#Color_Code")));
Maybe you should edit styles.xml at values-v14 folder.Because your min version is 19.
I found some questions about this problem around the web. Unfortunately, everything i try so far, has been unsuccessful.
Has the title say, i need to change the background color of my action bar.
The project have a min sdk of 9, and max sdk of 19.
I have create in my res/values folder, an xml file:
red_actionbar.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light">
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#color/red</item>
</style>
</resources>
the colors.xml stored in res/values
<resources>
<color name="red">#FF0000</color>
</resources>
and the part of the manifest where i change the theme
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomActionBarTheme" >
But nothing changes. Where is the problem? The application accepts the code because if i change ths:
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light">
to
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar ">
it does change the theme of my app, so the problem is in the style but I don't know how to solve it.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">#color/red</item>
<item name="background">#color/red</item>
</style>
</resources>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">#color/red</item>
<item name="background">#color/red</item>
</style>
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
you need both android:background and background items. The former is for newer versions of android that support ActionBar natively. The latter is for older android versions.
EDIT
instead of <resources> use
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
From SDK 21
to change Action Bar background color, add this to ActionBarTheme, and the two colours are to be different or it will not work (thanks to #Dre and #lagoman)
<item name="colorPrimary">#color/my_awesome_red</item>
<item name="colorPrimaryDark">#color/my_awesome_darker_red</item>
Try this:
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/red</item>
<item name="background">#color/red</item>
</style>
Try this.
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary"> #6699FF </item>
</style>
You can change #6699FF color according to your choice (or use a color resource).
try to use
parent="Theme.AppCompat.Light"
instead of
parent="#style/Theme.AppCompat.Light"
I have applied the following code in values-v11 folder
styles.xml
<style name="actionBarTheme" parent="android:Theme.Holo.Light">
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<style name="MyActionButtonOverflow" parent="#android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#drawable/action_item_btn</item>
</style>
But it not changing the overflow icon, all the other items in this theme is working fine but not this one, am i missing anything ?
i want to apply these styles above 4.0 version
But you have the styles in values-v11
Also note
parent="android:Theme.Holo.Light" // in your code
to
parent="#android:style/Theme.Holo" // mine
It should be in values-v14
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyTheme" parent="#android:style/Theme.Holo">
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<style name="MyActionButtonOverflow" parent="#android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#drawable/ic_launcher</item>
</style>
</resources>
Snap
Forget how the ui look's this is for testing. But you see the launcher icon as the overflow menu icon.
Edit:
This is my test sample
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarDivider">#color/red</item>
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#FF9D21</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText"
parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/red</item>
<item name="android:textStyle">bold</item>
</style>
<style name="MyActionButtonOverflow" parent="#android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#drawable/launcher</item>
</style>
<style name="ActionButton" parent="#android:style/Widget.Holo.Light.ActionButton">
</style>
</resources>
Colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#FF0000</color>
</resources>
Snap
i think you should do the following :
<style name="MyCustomTheme" parent="style/Theme.Holo">
<item name="android:actionOverflowButtonStyle">#style/MyCustomTheme.OverFlow</item>
</style>
<style name="MyCustomTheme.OverFlow">
<item name="android:src">#drawable/my_overflow_image</item>
</style>
You can set it programmatically in Java like this:
toolbar.setOverflowIcon(getResources().getDrawable(R.drawable.your_icon, null));
I created a custom title bar for my application but I am having some problems implementing it. I want to change the color and the appearance for the text and title bar
The layout of the styles.xml is as below:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme">
<item name="android:tabWidgetStyle">#style/LightTabWidget</item>
</style>
<style name="MyWindowTitleBackground" parent="#android:style/WindowTitleBackground">
<item name="android:background">#android:drawable/title_bar</item>
</style>
<style name="MyWindowTitle" parent="#android:style/WindowTitle">
<item name="android:singleLine">true</item>
<item name="android:windowTitleSize">40dip</item>
<item name="android:textAppearance">#style/MyTextAppearance</item>
<item name="android:shadowColor">#BB000000</item>
<item name="android:shadowRadius">2.75</item>
</style>
<style name="MyTextAppearance" parent="#android:style/TextAppearance.WindowTitle">
<item name="android:textColor">#3A6629</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="LightTabWidget" parent="#android:style/Widget.TabWidget">
<item name="android:textSize">20px</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#FF5721</item>
</style>
</resources>
And I have added that theme in the manifest file as follows:
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#android:style/Theme.Light">
<activity android:name="LAFoodBankAboutUs" android:label="#string/app_name" android:theme="#style/MyTheme">
What do I have to do to show the custom title bar?
By now (after some years), the Toolbar is available. It features a lot of customization possibilities and is also available via the Support Library