Holo Theme and SDK minimum - android

setting the sdk minimum 15, should I use Theme.Holo and not Theme.AppCompat
And instead, it is always as if I had given compatibility for Android versions 2.1 and higher.
In this guide: http://developer.android.com/training/basics/actionbar/adding-buttons.html
when I have to add the search action, the ActionBar, are forced to use xmlns: yourapp = "http://schemas.android.com/apk/res-auto"
to be able to give the right showAsAction ...
Same problem to set the Holo theme, this is not available, and returns me error (You need to use a Theme.AppCompat theme with this activity), and are forced to use AppCompat.
I then tried to create a new project with SDK minimun 16, thinking that the problem was on the 15th, and when I go to
res \ values ​​\ styles.xml
I always find parent = "Theme.AppCompat.Light.DarkActionBar"
The only way to use Holo, is creating a project with minimum 21 SDK.

The only way to not use AppCompat is to not use AppCompat. If you extend ActionBarActivity you have to use a theme that inherits from Theme.AppCompat. If you want to use Holo themes, you have to extend Activity.

Related

Removing Sherlock Actionbar library Theme not found

I have removed the ActionBarSherlock library and adapted my code.
Now I get errors in my style.xml
<style name="Theme.MyTheme" parent="Theme.Sherlock.Light">
What do I have to use instead of the Sherlock.light theme?
If you are using AppCompat library, use AppCompat.Light
#style/Theme.AppCompat.Light
else Try using Holo.Light.
#android:style/Theme.Holo.Light
If you are migrating to appcompat-v7, you need to migrate all Sherlock references to their corresponding AppCompat equivalents. This includes switching custom themes to inherit from Theme.AppCompat (e.g., Theme.AppCompat.Light).
You might consider installing Android Studio, then creating a scrap project using the new-project wizard. The defaults will use appcompat-v7, and you can examine the newly-created project to see what it uses, to help you determine how to change your Sherlock references.

Extending AppCompatActivity not letting me use Holo or Material themes

I'm trying to create an app with android:Theme.Holo.Light and extending the Activity by AppCompatActivity. Android is throwing errors saying that I must use AppCompat theme.
My question is:
If I don't extend AppCompatActivity, I don't get material look in API level below 21 and if I extend Activity and set Holo theme, I don't get any errors but at the cost of missing the Material feel in the older devices. How do I overcome this limitation?
You need to use Theme.AppCompat if you are extending AppCompactActivity
You can use Theme.AppCompat. It is similar to Theme.Holo

Android - How to use HoloTheme with AppCompat v22+

I don't really like Material design's spinner, and AppCompat doesn't contain the Holo Theme anymore. Should I revert back to AppCompat when it still supported Holo Theme or is there another way ?
With AppCompat v22, if you are using an AppCompatActivity you have to use an AppCompat theme.
If you try to use another theme you will receive:
Caused by: java.lang.IllegalStateException: You need to use a
Theme.AppCompat theme (or descendant) with this activity.
The only way to use a Holo Theme is to use a lower version.
e.g.
compile 'com.android.support:appcompat-v7:19.1.0'

android:Theme.Material.Light requires API level 21 (current min is 8)

I want to use Material Theme in my application which has minimum sdk version of 8. As per docs - "The material theme is only available in Android 5.0 (API level 21) and above. The v7 Support Libraries provide themes with material design styles for some widgets and support for customizing the color palette." Does it mean I can use it if I add v7 Support Libarary in my project? Because after adding this library I got the following error:
android:Theme.Material.Light requires API level 21 (current min is 8).
Or maybe I understood something wrong? Any suggestion will be appreciated. Thanks in advance.
For this you need to have 2 values folders.
One that exists by default, and another, you have to create in your res folder and name it values-v21.
In the default values folder, in styles.xml, use a theme other than Material theme.
And in the styles.xml of values-v21 folder that you created, use Material theme.
Android phone will automatically pickup the styles.xml which it supports. If the phone supports Material Design (Lollipop devices), your app will use Material theme (values-21 folder).
If it doesn't (in phones running older Android versions), the default values folder will be used.
You need to use android:theme="#style/Theme.AppCompat.Light" theme to get a material design.
Make sure your min is 8 and your target is 21. And you're using build tools/sdk 21.
Pedro Oliveira is right with regards to Theme.AppCompat, but some essential information is missing in that answer.
A blog post titled appcompat v21: material design for pre-Lollipop devices! by Chris Banes from the Android team probably best answers the question of how to get Material Theme for API levels prior to 21.
To summarise, you need appcompat-v7 dependency:
dependencies {
...
compile "com.android.support:appcompat-v7:21.0.3"
}
After that, for dark version as your base theme, use:
<style name="AppTheme" parent="Theme.AppCompat">
</style>
And for light version:
<style name="AppTheme" parent="Theme.AppCompat.Light">
</style>
And if you're new to AppCompat, there are things you need to know, such as:
All of your Activities must extend from ActionBarActivity*. It extends
from FragmentActivity from the v4 support library, so you can continue
to use fragments.
*NB: more recently, ActionBarActivity has been deprecated in favour of AppCompatActivity.
But you really should read the whole Setup section of that blog post! (The information on Toolbar vs Action Bar, and some of the comments are also something you probably shouldn't miss.)
In your NameActivity.java file import the following:
import android.support.v7.widget.Toolbar;
Comment the previous one:
//import android.widget.Toolbar;
With this the problem is solved.

Changing theme in manifest Appcompat v7 (API 21) (you need to use an Theme.Appcompat theme)

While trying to update my app to a material design look, I added Appcompat v7 library to my project(last update), Everything works well for now but I'm forced to declare a theme in the manifest (wich I wasn't before working with Appcompat Lib).
Theme.AppCompat.Light
And when I change the theme in my app with
setTheme(pink);
the status bar color choosen with
name="colorPrimaryDark">#color/pink
stays the same color as in the theme declared in the manifest.
So here is my question how can I change the status bar color?
I found the proper solution to all this, the
setTheme(theme);
method should be called before
super.onCreate(savedInstanceState);
You can use getWindow().setStatusBarColor(color).

Categories

Resources