安卓之imageButton

安卓之imageButton_第1张图片
image.png
layout.xml:



    
package com.example.my_imagebutton;

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

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button = findViewById(R.id.button1);
        ImageButton imageButton = findViewById(R.id.image_button);
    }
    //4.在XML中添加onClick属性
    public void onButtonClick(View view){
        new AlertDialog.Builder(MainActivity.this).
            setTitle("对话框").setIcon(R.mipmap.ic_launcher).
                setMessage(R.string.d_string).show();
    }
    public void onImageButtonClick(View view){
                    new AlertDialog.Builder( MainActivity.this).
                    setTitle("对话框").setIcon(R.mipmap.ic_launcher).
                            setMessage("哈哈,被骗了吧").show();}
                            //自定义一类
            public  class MyOnClick implements  View.OnClickListener{
                                @Override
                                public void onClick(View view) {

                                }
                            }
    public class MyImageOnClick implements View.OnClickListener{
        @Override
        public void onClick(View view) {

        }
    }


}

string.xml

    My_imagebutton
    你觉得我会让你下载吗
    想下载战狼2吗,点我呀!!!


你可能感兴趣的:(安卓之imageButton)