Change Android EditText background color - android

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

Related

about semi-transparent image function in android

just a question wondering when I was working on my app
let say I have image which I want to make it semi-transparent but I don't want to add about image into the app (as in create another one and add it in)
is there a way to do it??
You have to set the alpha value of the image. ( If i understood you correctly)
If you load this Image in to a ImageView, you can set it from xml like this:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/your_image_in_res"
android:alpha="1"/>
where according to the developers site "alpha property of the view, as a value between 0 (completely transparent) and 1 (completely opaque). " Play with the value to get the desired effect.
If you have your image int the res/drawable folder, you can use it anywhere in your code. In xml almost all elements have the following parameter:
android:background="#drawable/im_your_image"
. You just have to set this in all places, where you want this to be your background, for the parent views background. (e.g. your MainActivitys RelativeLayout that you inflate in the onCreate funciton. You see the image is put only once in the package, but this way you can set it several times as a background.

How to make TextView's background to be transparent?

There is a tablelayout having four tablerows, the first tablerow contains a TextView :
As you can see the background of the TextView having the text "Vidy" is seen ! So how to make it transparent ? I tried to add android:alpha="0" to the attribute of the TextView but at runtime the text is not seen !
You can try:
android:background="#null"
Or:
android:background="#android:color/transparent"
Check also: Android Transparent TextView?
If you really need transparency, #Nermeen's answer is great, you can also get it done programmatically like:
myTextView.setBackgroundColor(Color.TRANSPARENT);
but as long as you have solid background color below, it's better due to performance to make your TextView's background color the same as the layout below (with alpha, app needs to redraw more regions). It won't really matter for such a simple layout, but it's worth remembering when you have many of them using transparency.

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.

Any way to remove the grey background from ImageButtons?

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"

how to give background color for button in android

i have three button which is arranged in table row .I gave background for the three button but it wraps the button .
For starters read my blog :-)
Now my suggestion is to use background definitions with gradients. They look nice and are simpler to create then background images. As I said in the blog you need three of them for the button to work as expected. I have a demo for you here: button_type_0.xml
You will also need to define the colours: colors.xml
and dimensions: dimens.xml
you might also want to consider different dimensions for various dpi values. for example I use half size corners and border for ldpi: ldpi/dimens.xml
Looks all very complicated at the beginning but it is worth it. In the end it will look like this:
declare new a new xml in the drawable folder with the image/color you can specify image for each event state.
and you can you can set this xml as you background
if your xml is 'res/drawable/abc.xml' then set background as
android:background="#drawable/abc"
You can also use ImageButton
<ImageButton
----------------------
android:src="#drawable/youimage"
/>
The benefit for ImageButton is that, no need of different image/color for highlight.

Categories

Resources