DrawableLeft fails to compile - android

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

Related

Android ImageButton display error

I am developing an android app, I am trying to use the android image button. I have placed my image in the drawable folder and have this in my xml code:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/PanicBtn"
android:layout_marginTop="53dp"
android:src="#drawable/panicbtn2"
android:background="#ffffffff"
android:contentDescription="" />
but each time I try to clean or debug the project, i keep getting this error:
Error:(28, 22) No resource found that matches the given name (at 'src' with value '#drawable/panicbtn2').
Kindly help.
Sometimes, keeping the resource or image in your case in Drawable folder doesn't get added to ItemGroup/resource group.
You can simply open the .csproj file of your project and validate that if the image name is present in the < ItemGroup > section.. it must be like below if your image name and extension is panicbtn2.png:
<AndroidResource Include="Resources\drawable\panicbtn2.png" />
If it's not present there, then you can add the same there or you can right click the drawable folder and choose add files and simply add the file again through IDE/Visual Studio. That might help.
The error already states:
No resource found that matches the given name
Have you place a resource in drawable with that specific name "panicbtn2"?
Cheers.

no resource found that matches the given name?

This is driving me mad. My project compiled fine a moment ago. I made some minor change somewhere else, and now I'm getting this error. Here's the error message in full:
no resource found that matches the given name (at 'layout_above' with value '#id/blank_view").
Here's my XML file where the error is occurring:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="#dimen/margin_right"
android:layout_above="#id/blank_view"
android:src="#drawable/button" />
<View
android:id="#+id/blank_view"
android:layout_width="match_parent"
android:layout_height="#dimen/margin_bottom"
android:layout_alignParentBottom="true" />
</RelativeLayout>
How in the hell could it be failing to find a resource with the name "#id/blank_view" when that resource is just below it in the file?
Btw, the reason I have my layout like this is that I want the ImageButton to be aligned to the bottom of my relative layout, but offset up by a margin. For some reason, those two attributes (layout_alignParentBottom and layout_marginBottom) don't mix well in the same view.
I should also point out that this happened earlier as well, but I just removed the reference that was giving AndroidStudio such a problem, rather than trying to fix it. This, however, is too important to wave away like that.
This happens because the xml is parsed in a linear fashion and the views/objects created in a top to bottom order. So your xml tells the view builder to put your ImageButton above an item that does not exist yet.
Just move it below the blank view and the error should go away.
Try to add the property to your view:
<view
android:id="#+id/blank_view"
android:layout_width="match_parent"
android:layout_height="#dimen/margin_bottom"
android:layout_alignParentBottom="true"
android:layout_below="#id/btn"
/>
And remove:
android:layout_above="#id/blank_view"

Facebook login button widget no resource identifer

I have inherited some code and I'm working on it, however, when I try to build it I get the following issue:
activity_login.xml:26: error: No resource identifier found for attribute 'login_text' in package
My button xml is as follows:
<com.facebook.widget.LoginButton
xmlns:fb="http://schemas.android.com/apk/res-auto"
android:id="#+id/facebookBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:textColor="#color/white"
android:textAppearance="#android:style/TextAppearance.Small"
android:gravity="center"
android:onClick="facebookBtnClick"
android:paddingLeft="30dp"
fb:login_text="#string/loginWithFacebook"
/>
I have also tried putting in xmlns:fb="http://schemas.android.com/apk/res/com.facebook.widget"
but this didn't work for me either, if anyone has any suggestions I'd greatly appreciate it
You can find info here https://developers.facebook.com/docs/android/upgrading-4.x
Style attr tags are now namespaced to avoid conflicts. Apps will need
to add the namespace "com_facebook_" to their existing facebook sdk
style attrs.
So, use fb:com_facebook_login_text now.

Build Simple UI Lesson Sample

Ok, I have been following a lesson sample at the Android Developer site and the code was thus:
<LinearLayout 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:orientation="horizontal">
<EditText android:id="#+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
Apparently, the code should be fine, after worrying I typed it in wrong, I ended up copying it directly but the Console is telling me:
Description
error: Error: No resource found that matches the given name (at 'hint' with value '#string/edit_message').
Description
error: Error: No resource found that matches the given name (at 'text' with value '#string/button_send').
Now these values are defined in the strings.xml file. So I have no idea why I would be getting these errors.
To anyone who can help here is a big thank you in advance.
Try in eclipse project>clean . Sometimes eclipse give you errors like these. Or restart eclipse. Did you also make sure at your strings.xml you have something like this ?<string name="edit_message">Your intresting string.</string> sometimes if you use the 'gui resource adder' It gives mistakes. Check inside your xml.
make sure there is no capital characters or underscores in any file inside res.
Also , there must no any error inside the files of res and src ..
after that you have to clean the project as mentioned in previous answer.
Actually these errors prevent the R file to be updated which is necessary to access resources inside res file.

Using listItemFirstLineStyle in my own layout

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

Categories

Resources