Styling button with drawable background and drawable left - android

I suspect I'm going to have to do this the hard way, but here goes
I have this:
<Button
android:id="#+id/favouritesButton"
android:layout_height="wrap_content"
android:layout_margin="5sp"
android:text="#string/favourites"
android:drawableLeft="#drawable/shopping_basket_90x75"
android:enabled="false"
style="#style/BtnBigGreenLeft" />
Which gives me this
What the client wants is this (different drawable image but you get the idea)
Is this possible, or do I have to break it out into separate elements to get it to work?

Yea just break it down. It will solve you many future problems with any other solution.
And make the Linear layout the wraps it all clickable.

Sorry for my english.
If you want that all the picture will be clickable you can fix it simply
but if you want that only the green area will be clickable it should be harder

Sorry for my english again.
if you want whole thing clickable you only should to change the picture in the Paint program on your PC and change the correct pic to the new pic that you made and that it.
I hope it will halp you.

I think that you cant do this in one button.
Try to use the ImageButton on the image and break it down to 2 diference buttons(button and imagebutton) or just use the Paint program on your PC and put the image on the ImageButton background (the second I think easyer).

Related

Softening a TextView edges

I need to add a scrollable android TextView, which will show alot of text.
I want to achieve this kind of effect:
But I found no way of doing so.
Is there any good way of doing it?
Thank you!
try below properties to TextView
android:requiresFadingEdge="vertical"
android:fadingEdgeLength="32dp" //To change the gradient overlay height
The most convient way of doing this is creating a drawable. You can either make your own image in the image editing software of your choice or create a GradientDrawable. Make sure the colors go from white to transparent. Then place this drawable on top of the textview near the bottom.

Change Android EditText background color

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 :)

Android: using image instead of text on a button

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.

Creating icons in application activity and making them transparent

I want to create icons as something like this image or something like on the homepage of quickr. If I use custom gridview for this as in this (of course in my case I need the text below the image ), then adding listeners to that would be difficult I guess. Should I use buttons for that with the image and text below that provided the background is transparent? If so which layout I need to use? Or is there any icon view facility in android like other views such as button and imageviews, so that we can modify as per our requirement.
You should use button for that.
<Button
android:id="#+id/btnIconName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/iconimage"
android:text="IconTitle" />
For showing icon you should use android:drawableTop and for iocnTitle use android:text
Property.
I hope my answer is helpful to you.
GridView will be the best option to do this and why dont you ask your graphics guy to add text with image.

Best way to program buttons/images

I am designing something that will have a homepage close to the Google+ android app.
I'm having trouble figuring out the best way to do this? Should I create a button with text and set the background as the image? Should I create an image with the text already programmed in the actual picture or should I program the text and picture to be buttons.
Any suggestions from you guys on past projects?
You can use a Button with text to whatever you like and then place the image for that button above the text (using android:drawableTop)like so:
<Button
android:id="#+id/imageButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Photos"
android:drawableTop="#drawable/button_image" />
replacing buttton_image with your actual image. If you want the image in a different position (i.e. below text etc) use:
android:drawableLeft
android:drawableRight
android:drawableBottom
This would be how I would and do do it...
Since I am a newbie in android development I may be wrong but I suggest why not use a Grid View with each grid item haaving a textview and imageview.
My suggest to layout:
If you want to try something new in Android 4.0 , you can try GridLayout to layout , it can reduce the complicate of the nested layout , check out the blog about GridLayout:
http://android-developers.blogspot.com/2011/11/new-layout-widgets-space-and-gridlayout.html
You should write Buttons this way: http://developer.android.com/resources/articles/layout-tricks-merge.html
I normally use RelativeLayout but this is not important.
Write a class myClass extends RelativeLayout and inflate the XML with
LayoutInflater.from(context).inflate(R.layout.myCustomLayout, this, true);
I think this is best practice by Google.
use a regular button and set the android:drawableTop="#drawable/icon_...." value
Having the text burnt into you image is most certainly not the way to go.
One option for you is a GridView. You could also do this through a combination of Image button and scrollview. In my opinion, GridView is best and involves the least amount of code with most flexibility.
Remember that you can replace the button's background image with a state list drawable.

Categories

Resources