Im trying to customize my ActionBar, I´m following this tutorial by Android Developers --> Link, but it doesn´t channge, I specified the theme in the Android Manifest:
android:theme="#android:style/Theme.Holo" and, in my styles.xml:
And also I changed my styles.xml:
<style name="AppTheme" parent="Theme.AppCompat">
</style>
Also, I have the last version of the library:
And it is referenced in my App Grandle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.cheescake.juno"
minSdkVersion 14
targetSdkVersion 22
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:22.0.0'
}
I followed all the steps and I dont know why my ActionBar is in theme light yet. Maybe can be a stupid error and I didn´t understand something, but I have 2 days with this problem =(
Thanks !
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#android:color/white</item>
</style>
And in Manifest file
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
After specifying the colour of your theme e.g:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
....
</style>
Add the following line to the AndroidManifest.xml file
<application
...
android:theme="#style/AppTheme" >
....
Related
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 :)
I'm new to android studio and I have a new version installed (version 1.5.1).
For some reason I keep getting an error message (every time I use an app theme) saying that there were rendering problems: styles missing.
I looked online for solutions, but most of them are outdated or just do not work.
Thanks for any help.
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.easycodingplus.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Build gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.easycodingplus.myapplication"
minSdkVersion 8
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.1.1'
compile 'com.android.support:design:23.1.1'
}
just change your style.xml file like this
<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>
and then, go to
File > Project Structure > app >
and set (both should be same with latest version )
source compatibility : 1.7
Target compatibility : 1.7
you have to include the dependencies for design which is like this, this will be added under the dependencies block of the app module of the build.gradle
compile 'com.android.support:design:23.1.1'
it should be something like this ..
you need this support library as CoordinatorLayout, AppBarLayout and FloatingActionButton part of it
make a style in the style file
<style name="AppTheme" parent="Base.Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and reference that in your AndroidManifest file
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">// like this
Please ensure you have the lateset AppCompat library listed as a dependency in your build.gradle file:
com.android.support:appcompat-v7:23.1.0
Can you post which style the error is referring to? You may need to add a style to your res > values > styles folder. Something in your code is probably referencing a style that does not exists in that folder.
try this way:
keep your internet connection
go to "file" in android studio toolbar click on "invalidate caches/Restart" and choose "invalidate and restart"
3 options
1.Select low-level API version
2.Add Base on styles.xml
3.Install previous SDK (if you want)
I also faced the same problem so what I did...go to sdk manager -->tick android 5.1.1 api level 22 and installed it....
then go to Preview window and select other version
I faced the same problem and these steps helped me solve it:
1. File > Other settings > Default Settings > Appearances & Behaviour > File encoding.
2. Change project encoding to windows-1252. Then:
3. File > Invalidate Chaches/Restart.
OR WORST CASE
Change the theme to Material light or something else, one of them should work.
I hope this helps.
When i go to clean project I am left with 3 errors and I am not sure what to do, code below. Please could someone help?
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- From:
file:/usr/local/google/buildbot/repo_clients/https___googleplex-
android.googlesource.com_a_platform_manifest.git/mnc-
release/frameworks/support/v7/appcompat/res/values-
v23/styles_base_text.xml -->
<eat-comment/>
<style name="Base.TextAppearance.AppCompat.Widget.Button.Inverse" parent="android:TextAppearance.Material.Widget.Button.Inverse"/>
<!-- From: file:/usr/local/google/buildbot/repo_clients/https___googleplex-android.googlesource.com_a_platform_manifest.git/mnc-release/frameworks/support/v7/appcompat/res/values-v23/themes_base.xml -->
<eat-comment/>
<style name="Base.Theme.AppCompat" parent="Base.V23.Theme.AppCompat"/>
<style name="Base.Theme.AppCompat.Light" parent="Base.V23.Theme.AppCompat.Light"/>
<style name="Base.V23.Theme.AppCompat" parent="Base.V22.Theme.AppCompat">
<!-- We can use the platform drawable on v23+ -->
<item name="actionBarItemBackground">?android:attr/actionBarItemBackground</item>
<item name="controlBackground">#drawable/abc_control_background_material</item>
</style>
<style name="Base.V23.Theme.AppCompat.Light" parent="Base.V22.Theme.AppCompat.Light">
<!-- We can use the platform drawable on v23+ -->
<item name="actionBarItemBackground">?android:attr/actionBarItemBackground</item>
<item name="controlBackground">#drawable/abc_control_background_material</item>
</style>
<!-- From: file:/usr/local/google/buildbot/repo_clients/https___googleplex-android.googlesource.com_a_platform_manifest.git/mnc-release/frameworks/support/v7/appcompat/res/values-v23/styles_base.xml -->
<eat-comment/>
<style name="Base.Widget.AppCompat.Button.Colored" parent="android:Widget.Material.Button.Colored"/>
Check out your build.gradle file and make the changes as below,
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.example.inzi.app"
minSdkVersion 9
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'])
compile 'com.android.support:appcompat-v7:23.0.0'
}
Check for the compileSdkVersion (should be 23), buildTiilVersion (should be 23) and also the dependencies ('com.android.support:appcompat-v7:23.0.0')...
Let me know if it works...
And mark it as an answer so that it would be useful to others...
I am trying to use Theme.AppCompat, but when I do the Action Bar simply disappear. There is no errors or whatsoever.
The thing is I'm using this exact setting on two more projects and they work just fine, not sure what changed.
I also tried changing support library version, parent theme, cleaning the project, rebuilding and invalidating cache. Wasn't sure if any of that would help but I did anyway.
I am using Android Studio 0.8.14
Correct me if I'm wrong but that's how I use Material Theme widgets and color palette on older API's, right?
Preview
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".ActivityLogin"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
minSdkVersion 14
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.2'
}
My answer should be as a comment but this is the only way I can reply.
Are you extending ActionBarActivity in your activity?
Have you tried the show() method in your activity?
I am currently trying to create an Android app using the Android L SDK version.
However, when trying to build my project using Gradle, I run into the following error:
"Error: Found item Style/AppTheme more than one time"
Which points to my res/values-v21/styles.xml
I know that in res/values/styles.xml there is a style "AppTheme" already defined, but as far as I know I was following the Android developers guide on using Android L. Perhaps someone can help me:
Here is my:
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-L'
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.mayuonline.ribbit"
minSdkVersion 'L'
targetSdkVersion 'L'
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:support-v4:20.+'
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="resume.kelseyhrubes" >
<uses-sdk android:minSdkVersion="L" android:targetSdkVersion="L"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
values/styles.xml
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#color/primary_light</item>
</style>
</resources>
values-v21/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
</style>
<style name="AppTheme">#color/primary
#color/primary_dark
#color/primary_light
</style>
</resources>
I apologize for the bad formatting, I hope everything is readable.
If anyone knows what I am doing wrong, please let me know. I just want to make an app with that sweet material design.