I know it is a known issue, but my ide(android studio) is saying that setContentView can't be resolved. In fact, it was working perfect well but I tried to import some android plugin but then I deleted all the plugin files I added. Then I noticed that setContentView wasn't recognized anymore.
I tried everything I found on SO (cleaning, rebuilding....). I read it is mainly related to the xml view files, but I have no error in these files. How can I do ?
Update :
when running gradle build, I get some success build. Then when I want to run the project, I get in my console
org.gradle.execution.TaskSelectionException: Task 'compileDebug' is ambiguous in root project 'NewsFeeder'. Candidates are: 'compileDebugAidl', 'compileDebugJava', 'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugTestAidl', 'compileDebugTestJava', 'compileDebugTestNdk', 'compileDebugTestRenderscript
Edit 2 : here's my layout
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="400px"
android:layout_height="800px">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:background="#color/white"
android:headerDividersEnabled="false"
/>
<ListView
android:id="#+id/right_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:background="#color/white"
android:headerDividersEnabled="false"
/>
</android.support.v4.widget.DrawerLayout>
Edit 3: I restart the ide, and now I get in the activity_main file
Failed to find style 'listViewStyle' in current theme (8 similar errors not shown) "?android:attr/listPreferredItemHeight" in attribute "minHeight" is not a valid format. (Edit) (3 similar errors not shown)
Try this,
Make sure that setContentView is in the onCreate Method, and that all the other required pieces of code are in the method. Here is a basic template to help you out
package com.example.app
import android.app.Activity;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
As mentioned you have deleted all plugins make sure some required plugins are still there in place.
You can check them from Settings > Plugins
It seems android plugins default tasks are missing so make sure you have
apply plugin: 'android'
in your module's build.gradle file.
EDIT(As per the discussion in comments) :
It seems you are using actionbarsherlock in your project make sure you have applied Sherlock theme in your AndroidManifest.xml file
Something Like this :
If you are using style.xml for you theming
In your style.xml
<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<style name="AppTheme" parent="AppBaseTheme">
//other style elements here or leave it blank
</style>
in your AndroidManifest.xml file
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
</application>
Related
There is an issue in the follow Android App where guidance is greatly appreciated. This application is to support a Renesas RX130 microcontroller and Texas Instrument CC2650 Bluetooth Low Energy hardware demonstration design. In the initial device scanning page the tile has a bright red background as shown below.
The tool bar has a Purple to Red gradient background.
Question: How can the Red Tile background be made transparent?
The application has two activities. Below are excepts from the AndroidManifest.xml file
<activity android:name="capsense.application.rx130_cc2650.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="capsense.application.rx130_cc2650.DeviceControlActivity"/>
<service android:name="capsense.application.rx130_cc2650.BLE_Service" android:enabled="true" />
Code from activity_main.xml, listitem.xml, toolbar.xml and MainActivity.java generated the first activity. Relevant sections of code is from the files are below.
Excepts from activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Excepts from toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher_background_rx130_cc2650"
app:popupTheme="#style/CustomerPopUpMenuStyle"
app:theme="#style/CustomerToolbarStyle"
app:titleTextColor="#android:color/white">
</android.support.v7.widget.Toolbar>
Excepts from MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(capsense.application.rx130_cc2650.R.layout.activity_main);
mScanning = false;
//Get User Interface Elements
Toolbar toolbar = findViewById(capsense.application.rx130_cc2650.R.id.toolbar);
toolbar.setTitle(R.string.app_label);
setSupportActionBar(toolbar);
The complete project is available on github Android_Mobile_App_RX130_CC2650
References:
Set transparent background of an imageview on Android
Toolbar with Gradient Background set title background transparent
There is a conflict in color from multiple source to background.
Don't use theme unless if needed, as
theme influence all the views and layouts inside the toolbar
style influence only the toolbar and does not interfere with views and layouts inside toolbar
Please try below options, one of which might work for you,
Option 1 (preferred): update CustomerToolbarStyle code as below
<style name="CustomerToolbarStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:background">#drawable/ic_launcher_background_rx130_cc2650</item>
<item name="android:title">#color/colorforeground</item>
</style>
update toolbar.xml code as below
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:popupTheme="#style/CustomerPopUpMenuStyle"
style= "#style/CustomerToolbarStyle"
app:titleTextColor="#android:color/white"/>
Option 2: set transparent background in CustomerToolbarStyle
<style name="CustomerToolbarStyle" parent="Theme.AppCompat.Light.NoActionBar">
<!-- set background color to transperant -->
<item name="android:background">#00000000</item>
<item name="android:title">#color/colorforeground</item>
</style>
Option 3: remove android:background from the CustomerToolbarStyle
<style name="CustomerToolbarStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:title">#color/colorforeground</item>
</style>
Option 4: remove app:theme="#style/CustomerToolbarStyle" from toolbar.xml
If above options not working, please check below links
Change Toolbar background color programmatically does not change Toolbar Title Background color
Text background issue on Toolbar
I am very new to android develop & Android Studio. I was trying to create a simple app with a text input field so that that user can input text. (Again very new to this and just messing around with android development/studio).
Anyway, when I've added the 'TextInputLayout' and then a input text field from the palette, I get the above error.
I have tried to refresh as hinted to me. Also tried uninstalling Android Studio, different APKs. I have tried some solutions from another post on stack-overflow by looking through the manifest file and the style.xml files and haven't had any luck.
Was wondering if anyone could help me resolve this issue again I am extremely new to android development and Programming in general, so it may be an easy fix but I've ran out of ideas LOL.
Below is the code I currently have my 'activity_main.xml' file.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="#string/input_text"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
This is an android studio bug with dependencies of support library. I also faced same problem few days ago.
Go to build.gradle file (inside app folder).
Then change the version of dependencies of support library -- replace 28.0.1-alpha3 to 28.0.1-alpha1
Then go to styles.xml file (at app/res/values folder) and add this item in your style named AppTheme.
<item name="textInputStyle">#style/Widget.Design.TextInputLayout</item>
First if you create themes in res file so, locate it in manifest file with android:theme="#style/Theme.xyz" and in the layout design you have to check the same theme is applied there or not.
In addition to above users answer, if you are unsure about how to determine which certain version of the support library you should upgrade or downgrade, let Android Studio choose that best applies to you. Simply target it by putting .+ symbol right after the main version of the library, which works pretty well for me.
Go to Gradle Scripts, open build.gradle(Module:app), replace the version of support library dependencies as following:
dependencies {
implementation 'com.android.support:appcompat-v7:28.+'
}
and then go to styles.xml file located at app/res/values folder and add this item
<item name="textInputStyle">#style/Widget.Design.TextInputLayout</item>in your style named AppTheme. .
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="textInputStyle">#style/Widget.Design.TextInputLayout</item>
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Hope it helps to others, too. Let me know
I'm using this https://github.com/makovkastar/FloatingActionButton library for FloatingActionButtons in my project.
On some smaller devices, for example the Acer Liquid Z4 (Android version 4.2.2, screen 480x800) or the Genymotion Galaxy S2 image (Android version 4.1.1, screen 480x800) the FABs have a black box around them:
I tried to narrow this down, removed any special stuff from my theme making it look like this:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
and also put the buttons in the most simple layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="de.immowelt.android.immobiliensuche.ui.FabTestActivity">
<com.melnykov.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
but the box remains. On the other hand I tried to recreate the effect with a new project but couldn't do it.
The box disappears when using the mini size version or disabling the shadow.
Any ideas on what my problem is?
PS: I tried cleaning the project ;)
I was using that library but then decided to make my own, set this as the background to an imageButton or something. I used a textview because all I needed was a +. It looks pretty good in my app.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Drop Shadow Stack -->
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<padding android:right="1dp" android:bottom="1dp" />
<solid android:color="#00262626" />
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<padding android:right="1dp" android:bottom="1dp" />
<solid android:color="#0D262626" />
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<padding android:right="1dp" android:bottom="1dp" />
<solid android:color="#26262626" />
</shape>
</item>
<!-- Background -->
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<solid android:color="#448AFF"/>
</shape>
</item>
</layer-list>
The problem was that the FloatingActionButton class makes use of a drawable called shadow.9.png for the shadow. I also had a shadow.9.png in my drawables and the library class obviously picked up the wrong one (mine).
Renaming my drawable solved the problem.
I use Eclipse and I'm trying to create an application using the new support-library-v7:21.+ from Lollipop.
Created my new project
imported in eclipse the support-library-v7
changed in project-properties of support library the line: target=android-21 with 21 target
changed the target of my application in 21
imported the library in my project
clean all
After all i still got the invalid R declaration. I restarted Eclipse and then, after re-importing the library, seem went! I created a Tolbar and a NavigationDrawer as well without problem - it works.
Now, i would like to put a CardView in my ListView items:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
>
<!-- A CardView that contains a TextView -->
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/codename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/versione"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/timestamp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
well, first error: No resource identifier found for attribute 'cardCornerRadius'.
I tried to delete the attribute, restart the application but I get a the following crash:
java.lang.RuntimeException: Binary XML file line #2: You must supply a layout_width attribute.
I don't understand what the problem is.
Adding the library
Gradle
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:cardview-v7:22.0.0'
Eclipse
Using android.support.v7.widget.CardView in my project (Eclipse)
Proper LinearLayout
As the error said, a LinearLayout needs a layout_width and a layout_heighth. Always.
I have outlined the steps that worked for me as an answer to this question. It should work.
I had the same issue.
Tried adding Eclipse->properies->Android->Libraries->Add = CardView is not there.
Tried Eclipse->properies->JavaBuildPath->Libraries->Add Jars->(select from CardView->libs) did not work.
what worked:
cardview->project.properites, add android.library=true if missing.
We need to do both the things add android.support.v7.widget.CardView as a library project and also add + check it's jar file in java build path
Go to File -> Import -> Existing Android code into workspace --> Browse (Go to sdk/extras/android/support/v7/cardview) --> Click ok --> Click Finish
Right click on cardview project --> Properties --> Android(Left Pane) --> Enable isLibrary (tick the checkbox) --> Apply --> ok
Right click on your project --> Properties --> Android(Left pane) --> Add (under library) --> cardview --> apply --> ok
right click on your project again --> build path --> configure build path -->under libraries-->add jar-->expand cardview-->expand libs-->select android.support.v7.widget.CardView.jar
under order and export-->check android.support.v7.widget.CardView.jar-->click
Hope it will work fine.
It is obvious that you didn't import the CardView support project as your main project's library. To import CardView library, you need to do this:
1, first, import CardView support library into you Eclipse. The process should be like this:
File-->Import-->Android-->Existing Android Code into Eclipse-->Browse-->.../sdk/extras/android/support/v7/cardview-->OK-->Finish. Then you will see project of android-support-v7-cardview in your Eclipse in which all resource and jar is.
2, add android-support-v7-cardview into your main project as a library. Just like this: right-click your project-->Properties-->Android-->Add, and select android-support-v7-cardview into your project.
And then, rebuild your project. Errors about CardView in your project will be finished.
Inside your build.gradle file (inside dependencies section) add the last versions for support library and cardView support library:
dependencies {
...
...
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.0.1'
}
i want to use Navigation Drawer in my app. according google documentation here, i write my UI code like this:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
MAIN LAYOUT IS HERE
</FrameLayout>
<!-- The navigation drawer -->
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
this is like google's own example but it gives me an error in layout preview:
Exception raised during rendering: DrawerLayout must be measured with MeasureSpec.EXACTLY.
i searched a lot about it, some people says that you have to put explicit values for android:layout_width and android:layout_height. when i do this everything is going to be OK but i dont want to put explicit values! because i dont know every device width and height... how i can fix that? whats the solution?
i already put android-support-v4.jar file in lib folder. i think its the latest version.
just right click on project >> select android tool >> select add support library .
this should work , just do same steps !