我剛剛創建幷包含工具欄的活動,我在工具欄中放置了一個勾號圖標,但是當我運行應用程序時,勾號圖標未出現在工具欄中,這是我的班級工具欄中的圖標不出現
package mediaclub.app.paymob;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.ListView;
import java.util.ArrayList;
import mediaclub.app.paymob.Adapters.ContactsAdapter;
public class AddMembersActivity extends Activity {
ArrayList<Contact> listContacts;
ListView lvContacts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_members);
listContacts = new ContactFetcher(this).fetchAll();
lvContacts = (ListView) findViewById(R.id.lvContacts);
ImageView checkContacts = (ImageView) findViewById(R.id.checkedId);
ContactsAdapter adapterContacts = new ContactsAdapter(this, listContacts);
lvContacts.setAdapter(adapterContacts);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.iconmenu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(android.view.MenuItem item) {
switch (item.getItemId()) {
case R.id.checkedId:
Intent i = new Intent(AddMembersActivity.this, AddMembersActivity.class);
startActivity(i);
return true;
}
return super.onOptionsItemSelected(item);
}
}
,這是菜單
<?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/checkedId"
android:icon="@drawable/checked"
android:title="@string/check"
app:showAsAction="always"/>
</menu>
這是XML文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#ffffff"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="mediaclub.app.paymob.AddMembersActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:backgroundTint="#3cb5a4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="91"
android:orientation="horizontal"
android:weightSum="100" >
<ListView
android:id="@+id/lvContacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</LinearLayout>
</LinearLayout>
很抱歉,如果在事情是不明確的,如果任何一個知道如何解決這個情況請你只回答我 對不起我的英文不好
發表您的XML以及 –
@quick學生請我編輯我的答案 – DevDev