当前位置: 移动技术网 > 移动技术>移动开发>Android > android的图片按钮(ImageButton)的案例

android的图片按钮(ImageButton)的案例

2020年08月10日  | 移动技术网移动技术  | 我要评论
运行效果,这里设置了两个图片按钮,开始游戏按钮和注销按钮在xml添加如下代码<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.a.

运行效果,这里设置了两个图片按钮,开始游戏按钮和注销按钮

 

在xml添加如下代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    android:background="@mipmap/wzbg"
    android:gravity="bottom|center_horizontal"
    tools:context=".MainActivity">


    <ImageButton
        android:id="@+id/start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#0000"
        android:src="@mipmap/kaishi"
        android:paddingBottom="60dp"
        />

    <ImageButton
        android:id="@+id/zhux"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#0000"
        android:src="@mipmap/zhuxiao"
        android:paddingBottom="35dp"
        />




</LinearLayout>

在java文件添加如下代码

package com.example.wangzhekaishiyoux;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        ImageButton start=(ImageButton)findViewById(R.id.start);
        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this,"您单击了开始游戏按钮",Toast.LENGTH_LONG).show();

            }
        });
        ImageButton zhux=(ImageButton)findViewById(R.id.zhux);
        zhux.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this,"您单击了z注销按钮",Toast.LENGTH_LONG).show();

            }
        });
    }
}

然后下面这里是这个案例的图片资源

图片按钮的一些属性说明

 

 

 

 

本文地址:https://blog.csdn.net/qq_44716544/article/details/107901011

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网