14

I have 3 buttons at the bottom of an app im creating, and I'm just trying to use some stock android icons instead of text or a combination of both. There is the andoid:drawableStart / top / bottom / etc commands but I just would like these icons to appear smack dab in the middle. There seems to be no easy solution for this? Here is what I am working with:

<RelativeLayout
    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:background="@drawable/calm"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".PiktuurMain" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" >

        <Button
            android:id="@+id/takepic"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/round" />

        <Button
            android:id="@+id/editpic"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_weight="1"
            android:background="@drawable/round" />

        <Button
            android:id="@+id/sharepic"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/round"
            android:drawableStart="@android:drawable/ic_dialog_email" />
    </LinearLayout>
</RelativeLayout>
Cœur
  • 37,241
  • 25
  • 195
  • 267
erp
  • 2,950
  • 9
  • 45
  • 90

3 Answers3

28

Use an ImageButton:

<ImageButton
        android:id="@+id/sharepic"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@drawable/round"
        android:src="@android:drawable/ic_dialog_email"
        />
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
5

You can use MaterialButton. It has more advantages than something else. like the ripple effect, theme, icon tint, shape appearance, and so on.

<com.google.android.material.button.MaterialButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minWidth="0dp"
    app:icon="@drawable/ic_baseline_sports_soccer_24"
    app:iconPadding="0dp" />

<androidx.appcompat.widget.AppCompatImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_baseline_sports_soccer_24" />

enter image description here

Also, you should set android:padding="Xdp" to get suit width.

beigirad
  • 4,986
  • 2
  • 29
  • 52
1

You can used ImageButton instead Button. below i show you footer layout

<LinearLayout
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="56dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="0dp"
        android:background="@drawable/trans_bg"
        android:gravity="center"
        android:padding="5dp" >

        <LinearLayout
            android:id="@+id/ib_add_ed_lay"
            style="@style/Bottombar2LinearLayout" >

            <ImageButton
                android:id="@+id/ib_add"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:background="@drawable/add_event_button_back" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/ib_map_ed_lay"
            style="@style/Bottombar2LinearLayout" >

            <ImageButton
                android:id="@+id/ib_map"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:background="@drawable/map_button_back" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/ib_call_cd_lay"
            style="@style/Bottombar2LinearLayout" >

            <ImageButton
                android:id="@+id/ib_get_route"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:background="@drawable/route_button_back" />
        </LinearLayout>
    </LinearLayout>

Add style in values\styles.xml

 <style name="Bottombar2LinearLayout">
    <item name="android:layout_width">30dp</item>
    <item name="android:layout_height">30dp</item>
    <item name="android:layout_marginLeft">40dp</item>
    <item name="android:layout_marginRight">40dp</item>
    <item name="android:layout_marginBottom">1dp</item>
    <item name="android:layout_marginTop">1dp</item>
</style>

Output: enter image description here

M D
  • 47,665
  • 9
  • 93
  • 114