how change button Icons in android? - android

i wish to adjust icons in my application that i'm about to devolp.
this is the link of the tutorial that i'm folowing .
"https://www.youtube.com/watch?v=lkadcYQ6SuY"
this is the example given and created in the tutorial .
now i don't have the reputation yet to post pictures to show you what i want BUT
simple i want arrows for back and forward (custom created) instead of textbuttons
anyone who can help me ... ?

You can use ImageButton, put your icon into drawable folder(if it doesnt exist, create it), and set it to your imageButton
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/yourImgName" />

You can create a simple Button and set its Background for picture.
<Button
android:id="#+id/button"
android:background="#drawable/help"
android:contentDescription="#string/help"
android:gravity="bottom"
android:onClick="showHelp" />
Or you can create ImageButton :
<ImageButton
android:id="#+id/sync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:contentDescription="#string/sync"
android:background="#android:color/transparent"
android:src="#drawable/sync" />

try the below code
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/your_image_name"/>

Related

ImageButton show nothing in RecyclerView

I have RecyclerView include ImageButton play each item. But when I run ImageButton show nothing.
https://gist.github.com/tugnt/98917e0a2293d6cddd2e0e6e21d3d4fb
<Button
android:src="#drawable/ic_speaker"
android:id="#+id/play"
android:layout_margin="#dimen/pd_3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
In your xml,see android:src property is not for button. It's imageview property. So use ImageView instead of Button or set android:background for Button
<ImageView
android:src="#drawable/ic_speaker"
android:id="#+id/play"
android:layout_margin="#dimen/pd_3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Now try this.
Below is your code, in this you have used the android:src="#drawable/ic_speaker" for the button.
<Button
android:src="#drawable/ic_speaker"
android:id="#+id/play"
android:layout_margin="#dimen/pd_3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
But src is for imageview, which doesn't support the button view. So use background instead of src and in the xml preview you cannot see the play button. Have a look at the below code, I have edited the code
<Button
android:background="#drawable/ic_speaker"
android:id="#+id/play"
android:layout_margin="#dimen/pd_3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Use the xml preview to see whether you can see the view or not, which helps to sort put the bug easily and save our time. Hope this is helpful :)

how to set image as background button

I am new in Android development.I created a simple project with a simple button.I'd like to set image as background (see image). I've used android:src="#drawable/id_image" and android:background="#drawable/id_image2" but the image does not appear on the entire surface of button.Any help would be appreciated
Android, you can use android.widget.ImageButton to display a normal “Button“, with a customized background image.
<ImageButton
android:id="#+id/top_bar_btn_right_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:src="#drawable/ic_filter" />
You might use android:src and android:background for adding two images.
when you add your button , you just go to the menu of properties and choose background / drawable and choose your image
You can try something like this
<RelativeLayout
android:layout_width="250dp"
android:layout_height="400dp"
android:background="your_background_goes_here"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="your_icon_above_background"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text_for_your_image"/>
</RelativeLayout>

I want to put image over button

I want to put png image over button i tried android:background but the png takes all the button what i want exactly is to use the logo png over button like this
the info logo is my png and "about" comes from the button text
u can use this:
android:drawableTop="#drawable/SomeIcon"
so then you get this:
<Button
android:id="#+id/damage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="about"
android:drawableTop="#android:drawable/ic_menu_info_details"/>
it works for me :)
You can use a FrameLayout. In a FrameLayout, the z-index is defined by the order in which the items are added, for example
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_text" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/my_drawable"
android:scaleType="fitCenter"/>
</FrameLayout>
In this instance, the ImageView would be drawn on top of the Button, along the bottom center of the Button.
You can check this thread
Basically, you can use:
<ImageButton
android:id="#+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/album_icon"
android:background="#drawable/round_button" />
As the thread says.
Take a RelativeLayout, place ImageView inside it. Now set onClickListener on RelativeLayout.
By this way you can create more complex buttons.
<RelativeLayout android:id="#+id/your_btn_id"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
</RelativeLayout>
you can use
android:drawableTop
to put drawable at top of Button and use appropriate padding to make it position well.
<Buttton
android:layout_width="99dp"
android:layout_height="99dp"
android:background = "#drawable/bg" />
bg is your custom image.

Android ImageButton: image with tranparent background

i want to write an application where the user can change the color scheme. I have Imagebuttons and the images on the buttons are pngs and have transparent background. but when i place them on the buttons they are not transparent anymore. could anybody help me with some code?
thanks!
Anne
Are you ensuring that android:background="#null" is set? Otherwise you'll have the gray button background. For example:
<ImageButton
android:background="#null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/my_transparent_png"
/>
write your layout for ImageButton as:
<ImageButton
android:src="#drawable/your_image"
android:id="#+id/your_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"/>
Hope this helps!

How to add image for button in android?

How can I add an image to a button, rather than text?
Rather humorously, considering your tags, just use the ImageButton widget.
Simply use ImageButton View and set image for it:`
<ImageButton
android:id="#+id/searchImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="#android:drawable/ic_menu_search" />
As he stated, used the ImageButton widget. Copy your image file within the Res/drawable/ directory of your project. While in XML simply go into the graphic representation (for simplicity) of your XML file and click on your ImageButton widget that you added, go to its properties sheet and click on the [...] in the src: field. Simply navigate to your image file. Also, make sure you're using a proper format; I tend to stick with .png files for my own reasons, but they work.
You should try something like this
<Button
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/qrcode"/>
the android:background="#drawable/qrcode" will do it
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="News Feed"
android:icon="#drawable/newsfeed" />
newsfeed is image in the drawable folder
The new MaterialButton from the Material Components can include an icon:
<com.google.android.material.button.MaterialButton
android:id="#+id/material_icon_button"
style="#style/Widget.MaterialComponents.Button.TextButton.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/icon_button_label_enabled"
app:icon="#drawable/icon_24px"/>
You can also customize some icon properties like iconSize and iconGravity.
Reference here.
Put your Image in drawable folder. Here my image file name is left.png
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="118dp"
android:layout_y="95dp"
android:background="#drawable/left"
android:onClick="toast"
android:text=" " />
You can create an ImageButton in your android activity_main.xml and which image you want to place in your button just paste that image in your drawable folder below is the sample code for your reference.
<ImageButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="49dp"
android:layout_weight="1"
android:onClick="prev"
android:src="#drawable/prev"
/>
Use android:drawableright or android:drawabletop,... attributes for buttons in xml file.
For example: in xml file add this attribute for a button:
Android:drawableleft="#drawable/ic_person"
or
Android:drawableright="#mipmap/ic_launcher"
you can use ImageView as Button. Create an ImageView and set clickable true after in write imageView.setOnClickListener for ImageView.
<ImageView
android:clickable="true"
android:focusable="true"`
android:id="#+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
and in Activity's oncreate:
imageView.setOnClickListener(...

Categories

Resources