when i create a new project in android studio i find the the activity class initially extends AppCompatActivity and i have to change it to extend
Activity instead.
but the issue that i am facing is, R class is not recognisable and i receive the error "Cant resolve symbol R". i posted the build.gradle
file below and it seems to me it has no errors.
also, after tryin to find out the solution, i checked all the xml files and i found that the style.xml "posted below" has error at "Theme.AppCompat.Light.DarkActionBar"
and android studio cant resolve it.
please let me know how to fix this error.
code:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.xxx.xxx);//cant resolve symbol R
}
}
style.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">//cant resolve symbol Theme+cant resolve symbol AppCompat
<!-- Customize your theme here. -->
</style>
</resources>
gradle.build:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.com.bt_11"
minSdkVersion 19
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:23.+'
}
You will have to change the theme to Holo Light or Holo Dark or Material theme as pasted below;
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
Related
i am using Android Studio and despite all the projects in the old projects folder are working fine, when i try to
create a new project, AS could not recognise AppCompatActivity class
please have a look at the build.gradle and the style folders
please let em know how solve it
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.com.myapplication"
minSdkVersion 19
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.0.1'
}
style:
<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>
</resources>
update: after : com.android.support:appcompat-v7:23.1.1
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not resolve com.android.support:appcompat-v7:23.1.1.
Required by:
MyApplication4:app:unspecified
> Could not resolve com.android.support:appcompat-v7:23.1.1.
> Could not get resource
'https://jcenter.bintray.com/com/android/support/appcompat-
v7/23.1.1/appcompat-v7-23.1.1.pom'.
> Could not GET
'https://jcenter.bintray.com/com/android/support/appcompat-
v7/23.1.1/appcompat-v7-23.1.1.pom'.
> Connection to https://jcenter.bintray.com refused
I am making simple demo of tab view .But on first line i am getting null pointer exception . I am getting null value from this method getActionBar() why ?
I will share you my class
import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
ActionBar actionBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actionBar=getActionBar(); /// <- this is the line causing issue
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}
// ---------- methods ---------------//
}
I get null value on the line actionBar=getActionBar();
here is my manifest file and style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
</style>
</resources>
app.grudle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.naveen.tabviewswipe"
minSdkVersion 15
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.2.1'
}
Your MainActivity needs to extend AppCompatActivity (instead of FragmentActivity). Also, you'll need to use a different method to get the ActionBar:
actionBar = getSupportActionBar()
This is because you're using the support library.
if you want to extend FragmentActivity, then you need to use non-appcompat theme i.e. Holo to get actionbar
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo">
<!-- Customize your theme here. -->
</style>
You should extends ActionBarActivity and use getSupportActionBar().
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" >
....
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.
I'm new to Android programming. I want to use Android Studio (I have the newest one, version 0.8.2), and style my Action Bar.
The Gradle throws the following error during the build process:
Error:Error retrieving parent for item: No resource found that matches the given name '#android:style/Theme.AppCompat.Light.DarkActionBar'.
Here's my style.xml file:
<resources>
<!-- Base application theme. -->
<style
name="AppTheme"
parent="#android:style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/SocialExitActionBar</item>
</style>
<style
name="SocialExitActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/tranparent</item>
</style>
</resources>
It's the same as the Google's documentation. In every question, I found, the answer was to add the appcompat Library. But I have the appcompat library added in my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.procode.socialexit"
minSdkVersion 11
targetSdkVersion 19
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:19.+'
}
Here's on pic:
link
Thanks for your help!
I had to remove the #android:style/ before each parent value.