日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android ImageButton示例代码

發布時間:2025/3/11 Android 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android ImageButton示例代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1) XML File: activity_main

1)XML文件:activity_main

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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"tools:context="com.example.faraz.imagebutton_example.MainActivity"><ImageButtonandroid:id="@+id/imageButton1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/finger"tools:layout_editor_absoluteX="130dp"tools:layout_editor_absoluteY="155dp" /> </android.support.constraint.ConstraintLayout>

2) File: MainActivity.java

2)文件:MainActivity.java

package com.example.faraz.imagebutton_example;import android.app.Activity; import android.os.Bundle; import android.widget.ImageButton; import android.widget.Toast; import android.view.View; import android.view.View.OnClickListener;public class MainActivity extends Activity {ImageButton imageButton;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);addListenerOnButton();}public void addListenerOnButton() {imageButton = (ImageButton) findViewById(R.id.imageButton1);imageButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {Toast.makeText(MainActivity.this, "You Clicked Image Button!", Toast.LENGTH_LONG).show();}});}}

Note: Remember image button size should be 100dp and 50dp. You can resize it, but should not be very large.

注意:請記住,圖像按鈕的大小應為100dp和50dp。 您可以調整它的大小,但不要太大。

Output

輸出量

After executing your code, you get an image. Actually this is not only an image, but a button containing an image. As you click on the image button a toast message is displayed as “You Clicked Image Button”.

執行代碼后,您將得到一張圖像。 實際上,這不僅是圖像,而且是包含圖像的按鈕。 當您單擊圖像按鈕時,烤面包消息將顯示為“您單擊圖像按鈕”。

翻譯自: https://www.includehelp.com/android/ImageButton-Example-Code.aspx

總結

以上是生活随笔為你收集整理的Android ImageButton示例代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。