美文网首页
android 点击按钮出现提示

android 点击按钮出现提示

作者: 池瑶瑶 | 来源:发表于2022-04-25 11:46 被阅读0次

    activity_main.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"
        tools:context=".MainActivity">
        <Button
            android:id="@+id/botton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
    

    MainActivity.java

    package com.example.zjy.a102901;
    import android.database.sqlite.SQLiteDatabase;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;
    public class MainActivity extends AppCompatActivity {
      private Button button;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            button=findViewById(R.id.botton);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(getApplicationContext(),"welcome",Toast.LENGTH_SHORT).show();
                }
            });
    
        }
    }
    

    相关文章

      网友评论

          本文标题:android 点击按钮出现提示

          本文链接:https://www.haomeiwen.com/subject/rtbwvctx.html