我在andorid中写了一个简单的代码
package com.hello.stringtest;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
String x = "\r\nHello\r\nHello1\r\nHello2";
Log.i("Hello", x);
Toast.makeText(this,x,Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
当我运行这个应用程序时,我希望在Log行中分开 你好 Hello1 Hello2
但是Logcat表中没有任何内容。任何人都可以解释为什么它没有在Logcat中显示。
答案 0 :(得分:4)
当我尝试使用代码时
Log.i("ACTIVITY1", "\rCreated");
Log.i("ACTIVITY2", "\nCreated");
只有ACTIVITY2出现在Logcat中。我想你的问题与\ r \ n有关。 从String x中删除\ r \ n。尝试\ n而不是。
另见this。 \ r \ n似乎适用于旧的Mac OS版本。
答案 1 :(得分:-1)
这是因为默认情况下Log.i
与log.d
相比优先级较低。要检查它,将logcat窗口更改为来自debug的信息,您可以获得优先级的完整参考
The priority is one of the following character values, ordered from lowest to highest priority:
V — Verbose (lowest priority)
D — Debug
I — Info
W — Warning
E — Error
F — Fatal
S — Silent (highest priority, on which nothing is ever printed)
此链接也可能有用 http://developer.android.com/tools/debugging/debugging-log.html#startingLogcat