SoFunction
Updated on 2025-03-11

How to add image function to buttons in Android

Create a my_login.xml file in layout. The code is as follows

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Andro
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:background="@drawable/app_icon"
    android:orientation="vertical" >
    <Button
      android:
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="@drawable/apply"
      android:textSize="25sp" >
    </Button>
    <Button
      android:
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="@drawable/apply"
      android:textSize="25sp" >
    </Button>
</LinearLayout>
--------------------------------------------------------------------------------------------------------------------------------------------
existdrawable-xxhdpiAdd pictures to
--------------------------------------------------------------------------------------------------------------------------------------------

Add the following code to Mainactivity:

LayoutInflater inflater = (mMainActivity);
  View layout=(.my_login,null);
  ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(, 2131099656);
   builder =new (contextThemeWrapper);
  (layout);
  (false);
  ().show();
  Button startOrder_btn=(Button) (.startOrder_btn);
  Button managerOrder_btn=(Button) (.managerOrder_btn);
  startOrder_btn.setOnClickListener(new OnClickListener(){
  public void onClick(View v) {
  //Add the code you want to implement  ();
  }
  });
  managerOrder_btn.setOnClickListener(new OnClickListener(){
  public void onClick(View v) {//Add the code you want to implement  ();
  }
  });

The above is what the editor introduced to you to add image function to the buttons in Android. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!