为什么不在Click和TextView上显示menuItem。 请任何人帮我显示我的menusItem。 (我使用app:actionLayout =" @ layout / login_icon_design")。 当我们删除app:actionLayout标记时,菜单就会出现。
//dashboard.xml file
在这里输入代码
// login_icon_design.xml
<TextView
android:id="@+id/qcId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="0dp"
android:text="Active"
android:textColor="@color/button_green"
android:textSize="9dp" />
// DashboardActivity.java
@Override
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.dashboard, menu);
final Menu m = menu;
final MenuItem mitem = menu.findItem(R.id.button);
TextView qcId= (TextView) mitem.getActionView().findViewById(R.id.qcId);
SharedPreferences pref=this.getSharedPreferences("MyPref",MODE_PRIVATE);
String refCode=pref.getString("refCode",null);
qcId.setText(refCode);
Intent intent = getIntent();
String str2 = intent.getStringExtra("balance");
menu.findItem(R.id.bal).setTitle("Avl. Bal. \u20B9" +str2);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.bal) {
} else if(id == R.id.profile){
Toast.makeText(this, "1", Toast.LENGTH_SHORT).show();
} else if (id == R.id.logout){
Toast.makeText(this, "2", Toast.LENGTH_SHORT).show();
} else if(id == R.id.event) {
Toast.makeText(this, "3", Toast.LENGTH_SHORT).show();
} else if(id == R.id.history) {
Toast.makeText(this, "4", Toast.LENGTH_SHORT).show();
}
return super.onOptionsItemSelected(item);
}
答案 0 :(得分:0)
你必须添加这几行
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);