我想在操作栏上添加三个或三个以上的图标,我已经尝试但是我的第三个图标没有在操作栏上。可以有人解释我如何在操作栏上添加第三个选项。如何解决此问题。
menu.xml文件
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appcompat="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools">
<item
android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/imgAdd"
android:title="@string/CreatePost"
android:orderInCategory="200"
android:icon="@android:drawable/ic_menu_add"
app:showAsAction="ifRoom"></item>
<item
android:id="@+id/menu_search"
android:title="menu_search"
android:orderInCategory="300"
appcompat:actionViewClass="android.support.v7.widget.SearchView"
appcompat:showAsAction="ifRoom"/>
</menu>
活动代码
public class AllPost_ActionBar extends ActionBarActivity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_post);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
// Inflate menu to add items to action bar if it is present.
inflater.inflate(R.menu.menu_main, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
return true;
}
}
答案 0 :(得分:0)
做这样的事情:
private static int? GetNextPhotoRateId(int photoRateId)
{
PhotoRate currentPhotoRate = photoRates.First(x => x.PhotoRateId == photoRateId);
if (photoRates.Count(x => x.Rate == null) == 0)
{
return null;
}
List<PhotoRate> notRatedPhotoRatesAfterCurrentPhotoRate = photoRates.Where(x => x.PhotoRateId > currentPhotoRate.PhotoRateId && x.Rate == null).ToList();
if (notRatedPhotoRatesAfterCurrentPhotoRate.Count > 0)
{
return notRatedPhotoRatesAfterCurrentPhotoRate.First().PhotoRateId;
}
return photoRates.First(x => x.Rate == null).PhotoRateId;
}
答案 1 :(得分:0)
使用menu.xml文件。如果您想要图标显示,则需要将 app:showAsAction =“ifRoom”更改为 appcompat:showAsAction =“always”。使用菜单项设置,您可以使用 app:showAsAction =“never”或 appcompat:showAsAction =“never”。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:appcompat="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:orderInCategory="300"
android:title="@string/action_settings"
appcompat:showAsAction="never"/>
<item
android:id="@+id/imgAdd"
android:icon="@android:drawable/ic_menu_add"
android:orderInCategory="200"
android:title="@string/CreatePost"
appcompat:showAsAction="always"></item>
<item
android:id="@+id/menu_search"
android:orderInCategory="100"
android:title="menu_search"
appcompat:actionViewClass="android.support.v7.widget.SearchView"
appcompat:showAsAction="always"/>
</menu>
菜单项按整数值android:orderInCategory
的升序从左到右排列(即100,200,300 ...... - >从左到右)。