package com.example.buttontest;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1=findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,"您已成功Giao化",Toast.LENGTH_SHORT).show();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView android:layout_width="match_parent" android:layout_height="wrap_content"
android:src="@drawable/giao12"
/>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Giao~!"
android:background="#66A2D6"
android:textColor="#FFFFFF"/>
</LinearLayout>
图片按钮
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@mipmap/qiaobiluo"
android:gravity="bottom|center_horizontal"
android:paddingBottom="20dp"
tools:context=".MainActivity">
<ImageButton
android:id="@+id/baba"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@mipmap/baba"
android:background="#0000"
android:layout_marginBottom="20dp"
/>
<ImageButton android:id="@+id/jiaobaba"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@mipmap/jiaobaba"
android:background="#0000"/>
</LinearLayout>
package com.example.imagebutton;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
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 baba=findViewById(R.id.baba);
baba.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,"sb",Toast.LENGTH_SHORT).show();
}
});
ImageButton jiaobaba=findViewById(R.id.jiaobaba);
jiaobaba.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,"sb",Toast.LENGTH_SHORT).show();
}
});
}
}