0

I want to display the image as the button, but when I use ImageButton, it displays a gray border around button. I want it to be all black so that it looks like it's just the flashlight in the image! Any ideas? (The image file is just a PNG file)

Here's my fragment_display_message.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.myfirstapp.DisplayMessageActivity$PlaceholderFragment"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:weightSum="1"
    android:background="@color/black" >

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:layout_gravity="center_horizontal" />

    <TextView
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:text="\n   It's a bit dark in here,\n       don't you think?\n\nLet's light it up by tapping\n         the flashlight!\n\n\n"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/flashlight"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

</LinearLayout>

3 Answers3

1

remove these lines from you layout

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tyczj
  • 71,600
  • 54
  • 194
  • 296
  • Thanks! But the gray border around the ImageButton is still there. :( Could there be something wrong with my PNG file?? –  Jul 07 '14 at 20:43
  • 4
    oh duh you are using an ImageButton so its going to have a grey border around it, use a normal ImageView instead – tyczj Jul 07 '14 at 20:46
  • OH! Thanks, so can I still use ImageView as a button? (I want something to happen when the user touches/clicks on it) –  Jul 07 '14 at 20:49
  • 1
    ImageView has an onClickListener also – tyczj Jul 07 '14 at 20:50
0

It may help to set a the ImageButton Style to Borderless.

style="@style/Widget.AppCompat.Button.Borderless"
Traendy
  • 1,423
  • 15
  • 17
0

use ImageView instead of ImageButton

Sejpal Pavan
  • 130
  • 10