I'm having this question about setting pictures for Buttons in XML :
I made some .png pictures I want to set as pictures instead of the buttons that I get in default when i create my android apps.. Now I loaded in the files into the drawable folder.. And how do I write in XML to get the right thing?
Is setting the button visible to false and adding a picture as background for it an option?
Because that's all the ways I thought about. Or is there a better way to do this kind of thing?
what I understood is that you want to set the picture in background. Do it like this in your Button tag:
android:background="#drawable/yourpicturename"
Add the png to the drawable folder that is under the res folder in your project (if you are using eclipse). Then in your XML file simply use android:background="#drawable/filename". Make sure to omit the file extension
You can use any of:
drawableTop, drawableLeft, drawableRight, drawableBottom
For example,
<Button android:drawableRight="#drawable/some_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Some text" />
The image some_image.png will be positioned to the right of your text in this case.
Related
I Just know that we can use fonts for text only by using the TypeFace class. But can anyone please confirm me about images.
I have added all my custom fonts(.ttf) inside asset/fonts folder. Placed some ImageViews in their appropriate place in my app. And trying to use fonts to set images on them.
I have googled for a long time, but unfortunately unable to find any satisfied hint or help.
Can any one please help me to go forward from the current step.
Placed some ImageViews in their appropriate place in my app. And trying to use fonts to set images on them.
ImageView accepts images. Whatever set of pixels or vectors are in a font, they are not images from the standpoint of ImageView. The simplest way to display material from a custom font is through TextView, though you are welcome to implement your own Drawable and attempt to use that with an ImageView, or draw straight to the Canvas (e.g., in a custom widget).
You can use font awesome. Import the android-iconify/1.0.6 jar library from http://repo1.maven.org/maven2/com/joanzapata/android/android-iconify/1.0.6/
and you can use IconTextView
<IconTextView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="10dp"
android:text="{fa-mobile}"
android:textColor="#9fd46c"
android:textSize="30dp"
/>
I am developing an Android app. There's this issue with the EditTexts, because in some devices the "background" is white (which is the way I want it), but on others is transparent, and makes the app less professional. Here's an image with the "white background":
On other devices the edit texts that say "Yo" and "Casa" are transparent, so the words mix with the map and its pretty awful. I have tried changing the background color in the android layout xml. The closest one was I believe #drawable/white, but slightly changes the position and size of the edit text, making them look like they're one and its even worst.
Here is an example:
Is there a nice way to approach this problem? I read somewhere that an option was to add a white background image to the edit texts, but seemed like a lot of trouble.
UPDATE
I tried adding a background image, but its the same as changing the background color to any color using the android:background, the edit texts get like smaller or something. I added a blue "delimiter" to the image and this is the result:
But I want them like in the first picture, not so close one to another.
This would be the code of the edittext layout XML, the other one looks very similar. Only by adding the android:background tag changes from picture 1, to picture 3
SOLUTION
To solve this what I did was set a background image and set its height in dp as follows:
<EditText
android:id="#+id/markerTitle"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/buttonModifymarker"
android:ems="10"
android:inputType="textPersonName"
android:text="TÃtulo"
android:background="#drawable/editwhite"
>
Why don't you try setting the background of EditText programmatically?
yourEditText.setBackgroundColor(Color.WHITE);
or...
yourEditText.setBackgroundColor(Color.parseColor("#ffffff"));
simply you can add android:background="#drawable/white" attribute to your element in layout xml. you can use a lot of color resource between the double quotes (like from android color resources).
put the following image which has a solid white background in the drawable folder (it may dont appear because it's white and this page's background is white also) right click under this paragraph and select "Save Image as".
and refer to it in your layout and you will get a result like the following image
if the issue continue after trying this, please show me your layout code or email me at : mohamed_hamed4158#yahoo.com , thanks for voting my answer :)
I've been working on my android calculator and i can't seem to insert an image instead of text on a button. For example sqrt I don't want to have sqrt written on my button i want the image of the symbol on it, the same goes for x^y and alot of others. I have my custom background of the button working just fine. Thank you for your help in advance :)
EDIT:
Thats not what i wanted i did manage to get my custom button and thats fine. On my button since its a calculator button i have android:text on it saying sqrt. I want to remove that and insert another png on my button showing the symbol of the square root instead of that text. Thank you for quick responses.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/imageName"/>
You can have both text and image (or no text) when using the attribute drawableTop, drawableBottom, drawableLeft and drawableRight.
And for positioning the image how you want, consider using: paddingTop, paddingBottom, paddingLeft and paddingRight.
You can do this by ImageButton:
<ImageButton
android:id="#+id/submitEmailButton"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_gravity="right" android:layout_marginRight="15dip"
android:background="#drawable/ic_submit" />
Here ic_submit is the image you want to show as a button.
I used this tutorial and it worked perfectly for me: http://www.mkyong.com/android/android-imagebutton-selector-example/
I haven't seen your code but basically you should remove the "text" tag from your xml and it should appear the image without text then.
I don't know if that's exactly what you were looking for or not, but I reccomend you to follow the tutorial and for sure it will work for you ;)
There are a number of alternatives you can try to implement to build your SQRT button:
draw the button as a 9-patch drawable so your SQRT symbol won't get distorted;
use a RelativeLayout with a button inside and implement a selector
You can simply set background for the Button and keep its text blank.
I have an ImageButton and I'd like to remove the ugly (IMHO) background that surrounds the Image. I could just add an ImageView, but they're very hard to get set perfectly in a Layout like the grey one pictured. [gravity "Center" doesn't make it go to the middle, just centers it Vertically.)
So any way to remove that?
Just use android:background="#0000"
(#0000 same with #00000000)
or
ImageButton imageButton = new ImageButton(this);
imageButton.setBackgroundDrawable(null);
The default background is not transparent.
So, just add the transparent color "#00000000" as you background, then you could solve it.
p.s. #00000000 is the transparent color
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
android:background="#00000000"
/>
You can keep the square box and just change its color like this:
android:backgroundTint="#color/colorPrimary"
works beautifully
I'm having the same problem but now it has been solved. If you are using "android:background="#null" it will resulted of no background at all and no button pressed animation will be appeared to the user.
Just adding this line of code to make an image button become flashing upon clicked. This is the proper way to alert the user an image button has been clicked.
"android:background="?android:selectableItemBackground"
just useandroid:background="#null" in your xml
if you set the
android:background
instead of
android:src
it should overwrite the gray background
Yeah. If you drag ImageButton that will usually ask for ImageSource. But the ImageSource(android:src) doesn't remove the gray background. It is an image that should be on top of background:
Instead of that try android:background in layout XML.
please use the Draw 9-patch format for the image b'use it is provided by SDK
1. From a terminal, launch the draw9patch application from your SDK /tools directory.
2. Drag your PNG image into the Draw 9-patch window (or File > Open 9-patch... to locate the file). Your workspace will now open.
The left pane is your drawing area, in which you can edit the lines for the stretchable patches and content area. The right pane is the preview area, where you can preview your graphic when stretched.
3. Click within the 1-pixel perimeter to draw the lines that define the stretchable patches and (optional) content area. Right-click (or hold Shift and click, on Mac) to erase previously drawn lines.
4. When done, select File > Save 9-patch...
Your image will be saved with the .9.png file name.
Use like this
android:background="#android:color/transparent"
android:src="#drawable/icon"
All proposed solutions remove the ripple animation (on tap)
Settings background tint mode to 'add' will remove the background and keep ripple animation:
android:backgroundTintMode="add"
If using Xamarin Forms it can be done like this in the xaml view. Set background to transparent.
<ImageButton BackgroundColor="Transparent"
i know how to set image/icon from our res/drawable
<ImageView android:id="#+id/ImageSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/android_green_3d"/>
If we set it directly from the code:
imageView1.setImageResource(R.drawable.android_green_3d);
But we can also get the icon from android.R.drawable like this:
imageView1.setImageResource(android.R.drawable.ic_menu_more);
How to set image/icon in xml id the source is android.R.drawable? Anyone know?
Thanks in advance.
Thats easy: change #drawable/ to #android:drawable/. Code completion didn't work in this case, so you should search in the GIT repository or online for the images and their names