我最近开始了创建android应用程序的学习过程,我使用IntelliJ IDEA 13.1.1,我正在遵循这个添加操作栏按钮的教程,我得到了错误cannot resolve symbol navutils
。我在网上搜索过,遇到了几个stackoverflow帖子(1和2),在那些帖子中,他们似乎在谈论通过build.gradle
解决问题,我不知道它是什么,似乎找不到这个文件。
这是我的DisplayMessageActivity.java
代码,到目前为止,应用程序似乎工作得很好,我能够发布文本并看到它,但这个动作栏按钮让我发疯。
package com.example.My_First_App;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;
public class DisplayMessageActivity extends Activity {
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// Get the message from the intent
Intent intent = getIntent();
String received_message = intent.getStringExtra(MyActivity.SOME_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(received_message);
// Set the text view as the activity layout
setContentView(textView);
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
我将非常感谢任何帮助在这个问题上,因为我卡住了,不能继续与教程
我想你错过了
import android.support.v4.app.NavUtils;
我没有看到你在任何地方导入NavUtils
。
添加import android.support.v4.app.NavUtils;
到您的导入