建设网站公司哪家性价比高,最新推广注册app拿佣金,网站漏洞,网站分类标准在调试代码的时候我们需要查看调试信息#xff0c;那我们就需要用Android Log类。
android.util.Log常用的方法有以下5个#xff1a;Log.v() Log.d() Log.i() Log.w() 以及 Log.e() 。根据首字母对应VERBOSE#xff0c;DEBUG,INFO, WARN#xff0c;ERROR。
1、Log.v 的调…在调试代码的时候我们需要查看调试信息那我们就需要用Android Log类。
android.util.Log常用的方法有以下5个Log.v() Log.d() Log.i() Log.w() 以及 Log.e() 。根据首字母对应VERBOSEDEBUG,INFO, WARNERROR。
1、Log.v 的调试颜色为黑色的任何消息都会输出这里的v代表verbose啰嗦的意思平时使用就是Log.v(,);
2、Log.d的输出颜色是蓝色的仅输出debug调试的意思但他会输出上层的信息过滤起来可以通过DDMS的Logcat标签来选择.
3、Log.i的输出为绿色一般提示性的消息information它不会输出Log.v和Log.d的信息但会显示i、w和e的信息
4、Log.w的意思为橙色可以看作为warning警告一般需要我们注意优化Android代码同时选择它后还会输出Log.e的信息。
5、Log.e为红色可以想到error错误这里仅显示红色的错误信息这些错误就需要我们认真的分析查看栈的信息了。
注意不同的打印方法在使用时都是某个方法带上(String tag, String msg)参数tag表示的是打印信息的标签msg表示的是需要打印的信息。
下面是我做的一个简单的LogDemo(Step By Step):
Step 1:准备工作(打开LogCat视窗) 启动Eclipse,在Window-Show View会出来一个对话框当我们点击Ok按钮时会在控制台窗口出现LogCat视窗.如下图 Step 2:新建一个Android工程命名为LogDemo.
Step 3:设计UI界面我们在这里就加了一个Button按钮(点击按钮出现Log日志信息)
Main.xml代码如下:
?xml version1.0 encodingutf-8?
LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:orientationverticalandroid:layout_widthfill_parentandroid:layout_heightfill_parent
TextView android:layout_widthfill_parent android:layout_heightwrap_content android:textstring/hello/
Buttonandroid:idid/btandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textPresse Me Look Log
/
/LinearLayout
Step 4:设计主类LogDemo.java,代码如下: public class LogDemo extends Activity {private static final String ACTIVITY_TAGLogDemo;private Button bt;public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);//通过findViewById找到Button资源bt (Button)findViewById(R.id.bt);//增加事件响应bt.setOnClickListener(new Button.OnClickListener(){Overridepublic void onClick(View v) {Log.v(LogDemo.ACTIVITY_TAG, This is Verbose.);Log.d(LogDemo.ACTIVITY_TAG, This is Debug.);Log.i(LogDemo.ACTIVITY_TAG, This is Information);Log.w(LogDemo.ACTIVITY_TAG, This is Warnning.);Log.e(LogDemo.ACTIVITY_TAG, This is Error.);}});}}Step 5:运行LogDemo工程效果如下