Issue with AppCompat and Themes in Android - android

I recently created a new project with minSdkVersion 15, compiled and targetedSdkVersion 21, along with a couple of activities. I would like to use the default holo dark theme for my app and according to the documentation I just need to use Theme.AppCompat. When I test this on my personal phone (running 4.4.2), I get the dark holo theme and what I expect. However, when I run the latest nexus emulator with Lollipop, the theme and the controls look completely different. For example, the switch in Lollipop shows up just as a slider, without the text specified for the on/off states.
Is there a way for me to keep a consistent look and feel (of how it looks like on my phone) without having to worry about the app completely looking different on newer devices?
Edit:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
</style>
<style name="AppThemeDialog" parent="Theme.AppCompat.Dialog">
<!-- Customize your theme here. -->
</style>
</resources>
Settings:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "placeholder"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
Pics:
Lollipop/Emulator version: http://i.stack.imgur.com/u8QhX.png
Kitkat/Phone version: http://i.stack.imgur.com/u8QhX.png

Many widget UIs have been updated to the new 'Material Design' look and feel with latest version of appcompat-v7, on purpose. So if you really want to resist the trend, you will have to manually override your widget UIs with your own background.

Related

Unable to view the Text View Dropped in Design view of android studio

I have recentely started learning android studio and I know nothing about the errors.
I am dropping the text and buttons to the design view but I am unable to see them.
[]
Here are a few errors that are apperaring at the top right corner.
[]
The errors say:
Failed to find style coordinatorLayoutStyle in current theme.
This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints.
Missing styles. Is the correct theme chosen for this layout?
Some fixes that i have tried after googling are:
In styles.xml changing
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
[]
Also i found that i should change:
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
to
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
But in place of alpha3 there is rc01
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
[]
Nothing worked for me, please need a detailed answer as I am new to android studio.
remove this from gradel
implementation 'com.android.support:appcompat-v7:28.0.0- alpha3
and add this
implementation 'com.android.support:appcompatv7:27.0.1'
implementation 'com.android.support:design:27.0.1'
like this
android {
compileSdkVersion 27
defaultConfig {
applicationId "e.lenovo.alldemo"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}

android.support.v7.widget.Toolbar VectorDrawableCompat IllegalStateException when using support lib 24+

I've started a new project in Android Studio and configured my gradle build settings. When I add an android.support.v7.widget.Toolbar to a layout, I get the following error when in design view. Keep note that this error only shows up when previewing with an API less than 21 (specifically APIs 16 - 19). Everything works fine when I preview with API 21 - 24.
I have looked at a number of solutions and tried them, but none have solved the issue. One thing I tried doing was adding this to my gradle:
vectorDrawables.useSupportLibrary = true
But that didn't solve the issue. I tried configuring my compiledSdkVersion to 23, buildToolsVersion to 23.0.3. This did not change anything. If I change the support library versions to 23.4.0 or below, then the issue is resolved. As soon as I change it back up to 24.0.0 or higher then it returns.
Clearing the cache, cleaning the project and rebuilding, and invalidating the cache and restarting did not solve the issue.
The following classes could not be instantiated:
- android.support.v7.widget.Toolbar (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when in the IDE
Exception Details
java.lang.IllegalStateException: This app has been built with an incorrect configuration.
Please configure your build for VectorDrawableCompat.
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:692)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:181)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:67)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:298)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:229)
...
invalid drawable tag vector
Here is my app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1" // https://developer.android.com/studio/releases/build-tools.html
defaultConfig {
applicationId "org.path.path"
minSdkVersion 16
targetSdkVersion 23
versionCode 0
versionName "0.0.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
ext {
supportLibVersion = '24.0.0' // https://developer.android.com/topic/libraries/support-library/revisions.html
}
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:cardview-v7:${supportLibVersion}"
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
}
My project build.gradle is using classpath 'com.android.tools.build:gradle:2.1.2'
This is the toolbar xml:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:minHeight="?attr/actionBarSize"
android:elevation="4dp"
android:background="#color/colorPrimary"
app:theme="#style/ActionBarThemeOverlay"
app:popupTheme="#style/ActionBarPopupThemeOverlay"/>
And finally, my styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<!-- ActionBar -->
<style name="ActionBarPopupThemeOverlay" parent="ThemeOverlay.AppCompat.Dark" />
<style name="ActionBarThemeOverlay" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:textColorPrimary">#color/text_on_primary</item>
<item name="android:textColorSecondary">#color/subtitle_on_primary</item>
</style>
Is this a bug, or am I just not able to use the support library versions 24 or higher? I'm not aware of any other configurations to change as the exception tried to direct.
Check this issue:
appcompat-v7 24.0.0 is incompatible with rasterized vectors
Make sure you are using gradle version greater than 2.0
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}

By running the App on versions below 22 Changes some views?

I am developing an app with minSdkVersion 11, targetSdkVersion 23 and compile/build tool version 23. On android versions, 5 and 6 my app works fine, but installing the app on versions below 22 modifies some layouts, like buttons and text fields disappear or color changes, help me with this.
Manifest File
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.khan.bilal.salamrides2">
<application
android:allowBackup="true"
android:icon="#mipmap/cc"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
Styles file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay"
parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay"
parent="ThemeOverlay.AppCompat.Light" />
</resources>
Build Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.khan.bilal.salamrides2"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
}
Screen Shot of android version 22(Works fine)
Screen Shot of android version below 22(problem occurs)
When you use an element that was introduced in API 21, and you try to show it on a phone with API 11, there surely will be a problem. For the older versions, you have to differentiate between the elements that you are showing - if some element is not meant to be used in API lower than 21, then you have to provide if-else check and if the API is lower than 21, then use some simple element that you are sure was supported even in API 11.
For example, if you want to use TextInputLayout, you surely can, as the library supports API 22+, but for the lower versions you should probably input text by adding classic EditText. You add both of them to your XML, hide them, and then based on user's API you show one or other.
Also, read this document.
https://developer.android.com/training/basics/supporting-devices/platforms.html
Especially this should help you get an idea what and how to do it:
private void setUpActionBar() {
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
Good luck :)

Android Theme.AppCompat not found - but Google instructions respected

I am fighting against Android and compatibility library AppCompat and I am loosing. I come here crying for help.
Since I would like to use a NavigationDrawer (using the code automatically generated by Android Studio) I have to start using the AppCompat library. My app does not work any more because the builder cannot find the theme AppCompat.
I followed all the steps here: https://developer.android.com/tools/support-library/setup.html#add-library
This is the gradle file "Module:app":
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "19.1"
defaultConfig {
applicationId "it.misc.application"
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':another-library-here.')
}
And this is the res/values/style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
The error is:
Error:Error retrieving parent for item: No resource found
that matches the given name
'android:Theme.AppCompat.Light.DarkActionBar'.
Since I did everything the doc says and I also removed/reinstalled the compatibility library as suggested in an answer to another StackOverflow question, I do not know what else I could try.
Could it be related to the fact that I am using API and build tools ver. 19 and the the Android Support Library 21.0.3? (I think not, but ...)
This is the new gradle, but building keeps failing:
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "it.autostradetech.orchestra.negoziante"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':orchestra.autostradetech.it.')
}
Nothing changes if I set minSdkVersion to 14, 7, 8, or any other random number.
It's not android:Theme.AppCompat just Theme.AppCompat. Only resources from framework have the prefix.
Also change the compile SDK version to 21. The support library version, target SDK and compile SDK versions should correspond.
Replace:
<style name="AppTheme" parent="android:Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
with:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
Try changing compileSdkVersion and targetSdkVersion to 21, and change this in your Project Settings also. If you really want to use the appcompat-v7 library, then I suppose minSdkVersion should be at least 14.
EDIT: And it needs to be Theme.AppCompat.Light.DarkActionBar, not android:Theme.AppCompat.Light.DarkActionBar.
Try this solution as suggested in this question.
File->Import (android-sdk\extras\android\support\v7). Choose
"appcompat"
Project-> properties->Android. In the section library "Add" and
choose "appCompat"

using AppCompat-21 on Lollipop device crashes

Recently I upgraded my nexus 5 to Lollipop. and I create an app using AppCompat-21. The styles under values-v21 are as follo
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
</style>
</resources>
but when I run the app, it crashes with the information:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
here is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "geone.businspector"
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
}
It runs great under the device pre-Lollipop...
I googled a lot and had no good solution. anybody met this before? ps: I'm using Android Studio 0.8.14 and I'm new to Android Studio. thx.
The error clearly states that you're using the wrong theme. The activities you're using are from the android.support package, these activities need a ThemeCompat theme, not the Theme.Material.Light, which is for activities in android.app package. Rewrite your theme like so:
<resources>
<style name="AppTheme" parent="Theme.AppCompat">
</style>
</resources>
And this error will be gone.
Under your values/styles.xml you would be using Theme.AppCompat.Light
Use the SAME parent theme for your values-v21/styles.xml as well. This will get rid of the error as it did for me.
On Lollipop devices the theme works like it actually should so no worries :)
So I had the same issue and I got soooo tired of Googling it and seeing persons say not to use the Material Theme. Not using Material Theme changes the actionbar to gray even when you set a color for it in styles.
Anyway, the fix is that the android templates created by android studio use import android.support.v7.app.ActionBarActivity; instead of import android.app.Activity; and extend ActionBarActivity instead of activity for the main class. Just change the main class to extend an Activity instead of an ActionBarActivity. Of course more changes will have to be made if you are not using a Blank activity.

Categories

Resources