- 在MainActivity.java文件中添加需要打印信息的代码:
package com.example.a01helloworld;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
private static final String TAG="MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v(TAG,"onCreate:Verbose 观察值");
Log.i(TAG,"onCreate:Info 信息");
Log.d(TAG,"onCreate:Debug调试");
Log.w(TAG,"onCreate:Warn 可能会出问题");
Log.e(TAG,"onCreate:Error 崩溃信息");
}
}
2. Logcat界面的搜索框中输入“onCreate”即可显示打印日志信息