我试图在操作栏上显示相机图标,但它不起作用。菜单显示并正常工作,但相机图标不显示。你能帮我吗?
提前谢谢。
菜单代码:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_camera"
android:orderInCategory="0"
android:icon="@drawable/ic_action_camera"
android:title="@string/action_camera"
app:showAsAction="always" />
<item android:id="@+id/action_delete"
android:title="@string/action_delete"
app:showAsAction="never" />
</menu>
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.cfb.daily_selfie" >
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_action_camera"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme" >
<activity
android:name=".DailySelfieActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DisplayPictureActivity"
android:label="@string/title_activity_display_picture"
android:parentActivityName=".DailySelfieActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="br.com.cfb.daily_selfie.DailySelfieActivity" />
</activity>
<receiver android:name=".AlarmNotificationReceiver" >
</receiver>
</application>
</manifest>
Bellow onCreate()
public class DailySelfieActivity extends ListActivity {
static final int REQUEST_IMAGE_CAPTURE = 1;
public final static String EXTRA_MESSAGE = "br.com.cfb.daily_selfie.MESSAGE";
private static final String TAG = "DS-DailySelfieActivity";
private final static int INTENT_ID = 322;
private SelfieViewAdapter mAdapter;
private SelfieRecord mSelfieRecord;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView selfieListView = getListView();
final View footerView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_view, null, false);
selfieListView.addFooterView(footerView);
mAdapter = new SelfieViewAdapter(this.getApplicationContext());
loadListAdapter();
setListAdapter(mAdapter);
// Create Alarm to take a selfie
Alarm mAlarm = new Alarm(getApplicationContext());
// Enable filtering when the user types in the virtual keyboard
// selfieListView.setTextFilterEnabled(true);
// Set an setOnItemClickListener on the ListView
selfieListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Display a Toast message indicting the selected item
Toast.makeText(getApplicationContext(), "position = " +position + " id = " +id
, Toast.LENGTH_LONG).show();
mSelfieRecord = (SelfieRecord) mAdapter.getItem(position);
Toast.makeText(getApplicationContext(), "Date = " +mSelfieRecord.getDate()
, Toast.LENGTH_LONG).show();
// Display Picture
Intent intent = new Intent(DailySelfieActivity.this, DisplayPictureActivity.class);
Bitmap mPicture = mSelfieRecord.getPicture();
intent.putExtra(EXTRA_MESSAGE, mPicture);
startActivity(intent);
}
});
}
Bellow OnCreateOptionsMenu
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_daily_selfie, menu);
return true;
}
答案 0 :(得分:0)
ic_menu_camera
怎么样?虽然我确实在其他地方看到ic_action_camera
的引用,但这并不适合我。我有权访问android:icon="@android:drawable/ic_menu_camera"
(请注意添加@android:drawable
)
或者,正如@acostela指出的那样,请确保它在您的drawable文件夹中仅使用
android:icon="@drawable/ic_action_camera"
。
答案 1 :(得分:0)
我原来的Activity正在扩展一个ListView,所以我更改并扩展了ActionBar并且运行良好。
谢谢你, 卡洛斯