skip to Main Content

This is the image button

this is the button image

image does not shown up as background of imageButton

this is screenshot of imageButton after putting it’s background as image shown

this is screenshot of imageButton after putting it's background as image shown

Here is complete content.xml

    <?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.meggabyte.comppec.MainActivity"
tools:showIn="@layout/activity_main">


<ImageButton
    android:layout_width="300dp"
    android:layout_centerHorizontal="true"
    android:layout_height="wrap_content"
    android:contentDescription="@string/desc"
    android:id="@+id/imageButton"
    android:layout_gravity="center_horizontal"
    android:src="@drawable/ic_action_name"
    android:cropToPadding="false"
    />

enter image description here

2

Answers


  1. Use this code instead:

     <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageButton" android:layout_gravity="center_horizontal" android:src="@drawable/admin"
            android:cropToPadding="false" android:background="null"/>
    
    Login or Signup to reply.
  2. You didn’t assign an image to your ImageView… You need a line in your XML that says

    android:src="@drawable/some_image"
    

    The background and source are different

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search