I wanted to put background image to my app.
I kept image in res>drawable-hdpi folder.
Seted my image view as:
<LinearLayout
android:id="#+id/tv_un"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10pt"
android:textColor="#444444"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="res/drawable-hdpi/capture.PNG"/>
But its giving me error in the form of tooltip on line:
error: Error: String types not allowed (at 'src' with value
'res/drawable-hdpi/capture.PNG').
Am i pasting image in wrong folder?
Or code is wrong??
Please help me.
try this, put capture.png in any drawable folder
android:src="#drawable/capture"
Replace
android:src="res/drawable-hdpi/capture.PNG"
with
android:src="#drawable/capture"
Hope it helps.
change
android:src="res/drawable-hdpi/capture.PNG"
with
android:src="#drawable/capture"
android:src="#drawable/capture"
put this.
Related
In my app, Talkback is not pronouncing the name of the button. Instead it's just pronouncing as "button".
Can anyone help me to do the task?
I tried the following xml
<Button
android:id="#+id/loginsuccess"
android:scaleType="fitXY"
android:layout_width="100dp"
android:layout_height="30dp"
android:background="#drawable/submit_button"
android:layout_alignParentRight="true"
/>
that's not working
You should add the following in button xml declaration:
android:contentDescription="buttonName"
I simply added a property android:contentDescription=" " in the xml file, Like the following
<Button
android:text="Login"
android:textSize="0sp"
android:id="#+id/loginsuccess"
android:scaleType="fitXY"
android:layout_width="100dp"
android:layout_height="30dp"
android:background="#drawable/submit_button"
android:contentDescription="login"
android:layout_alignParentRight="true"
/>
that solved the problem.
For reference it was because you didn't have android:text so there was nothing to read out.
You must Content description is set on Button. Like this android:contentDescription="login"
I facing the problem that, I cant add new image button to my XML file.I added my icons to Drawable, but It cannot show in image button. XML shows an error ImageButton class not found. How can I solve this ?
I got the following error in xml
The following classes could not be found:
- ImageButton (Change to android.widget.ImageButton, Fix Build Path, Edit XML)
Here is my xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="109dp"
android:src="#drawable/facebook" />
</RelativeLayout>
Why dont you try a simple button instead of image button. Here is a code i have on some of my buttons with image.
android:drawableTop="#drawable/three" : this is basically the image
android:background="#drawable/buttonstyles" : this is a style for the button. No need to use it. Or the other layout features i have.
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button2"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:background="#drawable/buttonstyles"
android:drawableTop="#drawable/three"
android:onClick="goToSettings"
android:text="Settings" />
I was using the interface builder and for some reason, it added this
tools:src="#drawable/ic_play_arrow_white_100dp"
Change it to this to make it work and display image in image button
android:src="#drawable/ic_play_arrow_white_100dp"
I had the same problem. My images were .ico and I had the same error message in the Graphical Layout tab in eclipse. I proved to transform the .ico images to .png images and then I deleted the .ico and I imported the .png to the project.
It was succesful.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="109dp"
android:src="#drawable/a" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="164dp"
android:src="#drawable/a" />
</RelativeLayout>
I think this not big issue. Your is right nothing wrong with you posted. In my eclipse it works fine.
First check images properly put in drawable folder with small letter naming convention. or if you only have it in /res/drawable-xhdpi/ please check this also. May use this background instead of src.
if you not not getting R cannot resolve with putting image in xml, then first Refresh project, if is not work then clean whole project, if this is also not work restart eclipse.
if you restart eclipse, then it not work, may be your project library not properly located.
Change extend Activity to extend AppCompatActivity in your Activity Class
You need to define the Button as ImageButton in java classes.
I am not able to add image. I downloaded the image and added it to res directory under drawable-mdpi. Then when I try to add the image on the view using imageView, it gives me this error
Couldn't resolve resource #drawable/ball01
Failed to convert #drawable/ball01 into a drawable
Here is my xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:layout_gravity="center"
android:textSize="32sp"
android:layout_above="#+id/button"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enlighten Me"
android:id="#+id/button"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_above="#+id/textView"
android:layout_centerHorizontal="true"
android:src="#drawable/ball01" />
</RelativeLayout>
What am I doing wrong here.
The directory name should be 'drawable-mdpi'. Using a hyphen instead of an underscore.
image name must Digital or lowercase 。 ide only identification.
I had this same problem, I had this image which I named Barcode and then saved it into my drawable folder, then I decided it would be better to have it named barcode with a small b, so I renamed it.
Then I checked if it would work, and I got the same errors as you, after changing the name in my xml to 'Barcode' with a big B, it worked.
solution for me: delete barcode image from drawable and add it again with the name I'm going to use for it, don't change the name while it is in drawable folder.
I had this problem on android studio.
if you close and open project and it continues, all you need to do is RIGHT CLICK on the particular image you put in your "res" folder (that's giving the problem) and refactor-RENAME. Remove spaces in the name of the file. that should do it.
I have the next problem: I use a lot the RelativeLayout, like the Android documentation is telling me to do. But, since few days, I don´t understand why, this is not working anymore:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/boton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/boton"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000" />
</RelativeLayout>
This is my layout, very simple. So, according to this one, the textView should be BELOW the button, but, instead, it appears OVER the button!
.
Сan anyone explain me what happens?
EDIT: The problem is not when I try to run it on a device, the problem comes when I see it on the graphical layout of the ADT Plugin for Eclipse...
I try this code it's working properly.
If your side not working properly Try to Clean build your project and then Run.
If still having problem then Try this
android:layout_below="#+id/boton"
remove above line with this
android:layout_below="#id/boton"
Because "+" create new reference to R.java file
This may be the issue.
try by removing the below line from your code
android:layout_marginTop="60dp"
Take the '+' sign out of the TextView's layout_below attribute. The '+' tells it to deine a new id. Without the '+' it should refer to the existing one.
I think your issue is the drawable for the background, since I am not seeing an image in your preview.
Having this issue is giving you a build error so the preview doesn't show the layout in its current state (it reverts to the last sucessful build). Either remove that line and save to see the preview or check to make sure that you have an image in your drawables folder titled "background"
Try this, without the drawable to check if it is working for you:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/boton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/boton"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000" />
</RelativeLayout>
I am trying to run it, and now, I know what´s the problem.
When running the app in a terminal, it is working properly, the problems comes when I try to see it on the graphical layout on the ADT plugin on Eclipse! Anyone with the same problem??
Add </RelativeLayout> at the end of your relative layout to close it.
I need to put my own image on some imageView. So that's why I created folder named "drawable" in res folder , and copy my Image in this folder , but now I don't know how to set this image to my imageView in XML code. Can anybody help? and sorry for English :)
In your layout XML file:
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/your_image_name"/>
Replace your_image_name with the name of the image file without the extension (e.g. if your drawable file is called img1.png, the src attribute should have a value of #drawable/img1).
Set it using android:src=""
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image_name" />
Try this.
<ImageView
android:id="#+id/YourImageViewID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/Your_Image_Name"
/>
This may help you.
//set background as your image by calling the android:background attributes in your xml
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/myimage"
/>
Note: you no need to create any drawable folder by default android project will contain
drawable-mdpi
drawable-hdpi
drawable-ldpi
you can put your image in that.
<ImageView
android:layout_width="150dp"
android:layout_gravity="bottom"
android:layout_height="150dp"
android:id="#+id/image1"
android:layout_marginTop="11dp"
android:background="#drawable/image1"
/>