Android - Removing the gray border of an imagebutton programmatically - android

I have an application that generates imageButtons and places them in a TableRow.
However, the imageButton has a gray border along the sides that weren't on the image in the drawable folder.
How can I programmatically remove these borders? So far, the solution I've seen use the xml properties in the layout but I can't use that solution since I programmatically generate my imageButtons.
Any ideas?

Found the answer.
imageButton.setBackground(null);

You can use
ImageButton btn = (ImageButton)findViewById(R.id.imagebutton);
btn.setBackground(null);
Good luck

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.

How can I add padding to the background image on a button programatically?

I'm creating a custom implementation that extends android.support.v7.widget.AppCompatButton. I am using setBackground(Drawable) in the button's constructor to put an image on the button, but want the image to be centered on the button with a little padding. How can I do this?
It sounds like you should be using ImageButton instead of Button. If you do so, you can take whatever image you'd normally use and create an Inset Drawable from it, and then use that as the src attribute of your ImageButton.
Say you have a drawable res/drawable-mdpi/mydrawable.png. You could create res/drawable/mydrawable_inset.xml as follows:
<inset
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/mydrawable"
android:insetTop="100dp"
android:insetLeft="100dp"
android:insetRight="100dp"
android:insetBottom="100dp"/>
Here's a layout that includes one ImageButton with just #drawable/mydrawable and a second with #drawable/mydrawable_inset:

Gridview with button and text

I am new in android I want to ask help how can achieve design like this that have 4 buttons ,icons and text. and it has icon in header part.
Thank you in advance.
First:Decide which layout should u use.I think u can use Gridlayout of 2*2.Or you can just use linearlayout and set weight.
Second:In gridlayout you can use button or Imageview or TextView(drawableTop).
for your images in the in the above screenshot which you have provided you can use Image Button in android and you can set their size according to you and for the header you can use any layout of your choice.
Thank you
Yes You Can
You can use many options GridView, CardView Or LinearLayout
, and for the icon header you Can Customize the Toolbar as described in the developer documentation here

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.

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