I'm trying to create a custom ListView layout similar to android.R.layout.simple_list_item_2. However, when I use the following in my XML I get an error saying "No resource found matching the given name ?android:attr/listItemFirstLineStyle".
<TextView
android:id="#+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/listItemFirstLineStyle" />
Can someone tell me how to rectify this or how to find the style properties so that I could copy them. I'm using Android 2.2.
Found the problem - android:attr/listItemFirstLineStyle was for an old version of the SDK I guess. For 2.0 and above - use android:attr/textAppearanceLarge NOT android:attr/listItemFirstLineStyle
http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/core/res/res/layout/simple_list_item_2.xml
Related
I will being by saying that I have seen SOME answers for this question on stackoverflow already, but only providing a quick 'fix' solution. I would like, if possible, to also understand WHY this is happening (an answer with some detailing).
Now to get to the question: I have just re-started android development, using Android Studio 2.2 . I have an ios app which I want to port to android (meaning, recreate it for Android). I have started with a basic template from Android Studio, added a Constraint Layout and 2 ImageViews using 2 PNG files that I have copied in DRAWABLE folder.
Without making any changes or whatsoever , when I try to build I get this error:
Error:(11) No resource identifier found for attribute 'srcCompat' in package 'x.y.z'. This happens for both images. Here is the layout 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/lib/x.y.z"
xmlns:app2="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="x.y.z.MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app2:srcCompat="#drawable/pngFile1"
android:id="#+id/imageView"
app2:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="8dp"
app2:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app2:srcCompat="#drawable/pngFile2"
android:id="#+id/imageView2"
app2:layout_constraintBottom_toTopOf="#+id/imageView"
app2:layout_constraintRight_toRightOf="#+id/imageView"
android:layout_marginBottom="8dp" />
Now, here are some things that I would like to understand, in order to have a proper answer to my question:
some of the other answers I have found on SO propose to change the default:
xmlns:app="http://schemas.android.com/apk/res-auto"
to:
xmlns:app="http://schemas.android.com/apk/lib/x.y.z"
It's true that this removes the error from the build, but what seems strange to me (with my little-to-none android experience), is that Android Studio creates then another similar line when i add the 2nd image:
xmlns:app2="http://schemas.android.com/apk/res-auto"
And as we can see, it uses this for the images, so the errors appear again.
I remember like one year ago i had worked on an app on Android Studio, and have used almost the same way of adding images / buttons with images and these problems were not there.
That's why I would also like to understand why this is happening and how to fix it properly.
Thanks in advance !
Fist of all you need to concentrate on the version of android studio you are using. You should also look at the minSdkVersion and targetSdkVersion.
Try to use android:src="" instead of app2:srcCompat=
app2:srcCompat= suports older APIs when loading vectorDrawable.
If you want to use it,then amend your build.gradile like,
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
For more information you can refer to this link
or you can refer to this answer at stackoverflow
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:background="#drawable/cooltext201199220690445" />
I just changed mine into like this and it worked for me
I just removed that srccompat and replace it with "background"
and i completely removed "xmlns:app2="http://schemas.android.com/apk/res-auto" hope this helps you :)
I am trying to program for Android 4.2 device but the book I have is teaches Android 4.0 called Beginning Android App Development 4. So, I am having problems running the first program targeted for Android 4.2:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is my first Android Application!" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="And this is a clickable button!" />
</LinearLayout>
error: Error: No resource found that matches the given name (at 'text'
with value
'#string/hello'). activity_main.xml /HelloWorld/res/layout line
7 Android AAPT Problem
[I18N] Hardcoded string "And this is a clickable button!", should use
#string resource activity_main.xml /HelloWorld/res/layout line
20 Android Lint Problem
[I18N] Hardcoded string "This is my first Android Application!",
should use #string
resource activity_main.xml /HelloWorld/res/layout line 15 Android Lint
Problem
I would like to where can I find the difference between 4.0 APIs from 4.2? Should I continue reading the book?
Well, that first error is simply because you haven't created a resource in your strings.xml called hello. The other two warnings are just because Android Lint wants you to use a string resource (like the first one), instead of hardcoding the strings.
Neither of these have anything to do with any differences between Android 4.0 and 4.2 however.
If you are still curious about the differences in these API levels, the Android documentation has plenty of information.
https://developer.android.com/sdk/api_diff/21/changes.html
https://developer.android.com/sdk/api_diff/22/changes.html
your problem ist not really a problem with APIĀ“S its just because you used a string that is not in strings.xml file(hardcode string). you can ignore it (should be just an advisement not a error) or just create a the string (only if you go to use that string more than once.
I know as soon as I post this question on stackOverflow it is going to be marked as duplicate but trust me I have tried every possible solution discussed under the same topic in StackOverflow.
I am trying to add Facebook SDK in my project . After adding it under my project->properties->Android (then add facebook adk as library) , when i try to create my xml file and use it shows me red cross next to it and no matter what i do I am not able to make this error go away. Please help me..Anything help is appreciated!!
The 'Unbound Prefix' error is due to having a custom namespace in your xml that is not accounted for.
You need to add another prefix to the top of your file. It should be similar to what I've wrote below, but with PREFIX replaced by the prefix you are using.
xmlns:*PREFIX*="http://schemas.android.com/apk/res-auto"
So, in the end, your file should look something like this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fb="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.facebook.widget.LoginButton
android:id="#+id/connectWithFbButton"
style="#style/com_facebook_loginview_default_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:text="#string/connect_with_facebook"
fb:login_text="#string/connect_with_facebook"
fb:logout_text="Connecting with facebook" />
</LinearLayout>
In this example I've added the prefix 'fb' and I have referenced it when using the fields login_text and logout_text :)
use
FacebookSdk.sdkInitialize(getApplicationContext());
before
super.onCreate(savedInstanceState);
Keep both library and project in the same workspace.
try to deleting this two lines
fb:login_text="#string/connect_with_facebook"
fb:logout_text="Connecting with facebook"
I currently have a code for a button in XML as such:
<Button
android:id="#+id/button1"
android:layout_width="250dp"
android:layout_height="62dp"
android:layout_gravity="center_horizontal"
android:drawableLeft="#drawable/ic_menu_slideshow"
android:text="Start Slideshow" />
However, I get an error for Error: No resource found that matches the given name (at 'drawableLeft' with value '#drawable/ic_menu_slideshow'). However, when I check on the graphical layout of the XML file, the stock drawable at ic_menu_slideshow is present. Why do I get this compilation error, and how would I fix it?
Try to replace #drawable/ic_menu_slideshow with #android:drawable/ic_menu_slideshow
Have you tried cleaning your project? A similar question was asked moments ago so keep an eye on that as well: Can't Resolve Android Resource Strings
I'm working on a couple of apps at the moment while I try to learn my way around the Android SDK. I had a bit of trouble recently with my layouts where I was defining, for example, an EditText element as such...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="#+id/price_per_pack"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/price_per_pack"
android:layout_alignParentLeft="true"
android:textSize="12pt"
android:text="Price Per Pack"/>
</LinearLayout>
The application was compiling correctly, however when I attempted to start the activity which utilizes this layout nothing would happen. Through a process of elimination I identified the id attribute as the troublesome one and while playing about I discovered that changing
android:id="#+id/price_per_pack"
to
android:id="#+android:id/price_per_pack"
solved my problem and the application behaved as expected. My initial attempt at declaring the id attribute was based upon examples in the SDK documentation so I'm wondering if somebody could explain to me why I needed to make the above change to get it working?
I'm sure that it won't make any difference but I'm developing using the android-mode.el emacs plugin and have a completely up-to-date copy of the SDK.
Thanks in advance.
From Android Documentation:
With the android package namespace in place, we're now referencing an ID from the android.R resources class, rather than the local resources class.
It looks like you might have some syntax errors in your code posted.