当我编辑时,当我编辑完成时仍然出错。这是我的代码 MainActivity
package com.example.actionbar;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
//ถ้ามีการเลือก actionเกิดขึ้น object ที่นำมาใช้จะเรียกชื่อobject นี้ว่า onOptionItemSelected()
public boolean onOptionItemSelect(MenuItem item){
//ใช้switch case ในการกำหนดว่าเมือ เลือก action นี้เเล้วทำอะไร
switch (item.getItemId()){
case R.id.action_search:
Toast.makeText(this,"Menu search is selected", Toast.LENGTH_SHORT).show();
break;
case R.id.action_settings:
Toast.makeText(this,"Menu setting is selected", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
return true;
}
}
现在我将字符串添加到 string.xml
<string name="action_search">Search</string>
这是我在 res/menu/main 中的代码
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:name="@string/action_search"
android:showAsAction="ifRoom"/>
这是我在 (android:label="@string/Theme.AppCompat.Light") 的清单错误中的代码。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbar"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.actionbar.MainActivity"
android:label="@string/Theme.AppCompat.Light" > <<<<<<<<<<<error
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是我在 R & Theme.AppCompat.Light 中的错误。
R cannot be resolved to a variable
No resource found that matches the given name (at 'label' with value '@string/Theme.AppCompat.Light')
我能怎么做 ??谢谢你