[Android Studio]1.2计数器

[Android Studio]1.2计数器_第1张图片

所有要改的代码如下: 

MainActivity代码:

package com.example.code02;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private int count=0;
    private TextView tvCount;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btnShowToast = findViewById(R.id.btnShowToast);
        btnShowToast.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "Hello World!",Toast.LENGTH_SHORT).show();
            }
        });

        tvCount=findViewById(R.id.tvCount);
        Button btnCount = findViewById(R.id.btnCount);
        btnCount . setOnClickListener (new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tvCount.setText(Integer.toString(++count)) ;
            }
        }) ;

    }
}

activity_main:




    

colors:



    #FF000000
    #FFFFFFFF
    #009688
    #EEEEEE
    #9E9E9E
    #008577
    #004A57
    #C550DA

strings部分我没动,但是代码可以在这里再改进,不过不影响功能

你可能感兴趣的:(Android,Studio,android,studio,android,ide,安卓开发)