我的操作栏太细了,菜单没有显示
my action bar is so thin and the menu is not displayed
[这是主要的 activity,其中没有显示菜单项,操作栏太薄了,我应该怎么做才能显示菜单项]
主要活动
public class MainActivity extends Activity {
public ListView listView;
//public ScrollView mScrollView;
public ScrollView mScrollView2;
public TextView mTextView;
private static final int CATEGORY_DETAIL = 1;
private static final int NO_MEMORY_CARD = 2;
private static final int TERMS = 3;
public RadioButton radEnable;
public RadioButton radDisable;
private static Resources res;
private Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
res = getResources();
listView = (ListView) findViewById(R.id.mylist);
//mScrollView = (ScrollView) findViewById(R.id.ScrollView01);
mScrollView2 = (ScrollView) findViewById(R.id.ScrollView02);
mTextView = (TextView) findViewById(R.id.txtNoRecords);
SharedPreferences settings = this.getSharedPreferences(
Constants.LISTEN_ENABLED, 0);
boolean silentMode = settings.getBoolean("silentMode", true);
if (silentMode)
showDialog(CATEGORY_DETAIL);
context = this.getBaseContext();
// showDialog(TERMS);
}
@Override
protected void onResume() {
....
}
/**
* checks if an external memory card is available
*
* @return
*/
public static int updateExternalStorageState() {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
//return true;
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
SharedPreferences settings = this.getSharedPreferences(
Constants.LISTEN_ENABLED, 0);
boolean silentMode = settings.getBoolean("silentMode", true);
MenuItem menuDisableRecord = menu.findItem(R.id.menu_Disable_record);
MenuItem menuEnableRecord = menu.findItem(R.id.menu_Enable_record);
// silent is disabled, disableRecord item must be disabled
menuEnableRecord.setEnabled(silentMode);
menuDisableRecord.setEnabled(!silentMode);
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Toast toast;
final Activity currentActivity = this;
switch (item.getItemId()) {
case R.id.menu_about:
AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
builder.setTitle(R.string.about_title)
.setMessage(R.string.about_content)
.setPositiveButton(R.string.about_close_button,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
}).show();
break;
case R.id.menu_Disable_record:
setSharedPreferences(true);
toast = Toast.makeText(this,
this.getString(R.string.menu_record_is_now_disabled),
Toast.LENGTH_SHORT);
toast.show();
break;
case R.id.menu_Enable_record:
setSharedPreferences(false);
// activateNotification();
toast = Toast.makeText(this,
this.getString(R.string.menu_record_is_now_enabled),
Toast.LENGTH_SHORT);
toast.show();
break;
case R.id.menu_see_terms:
Intent i = new Intent(this.getBaseContext(), TermsActivity.class);
startActivity(i);
break;
case R.id.menu_privacy_policy:
Intent browserIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://www.privacychoice.org/policy/mobile?policy=306ef01761f300e3c30ccfc534babf6b"));
startActivity(browserIntent);
break;
case R.id.menu_delete_all:
AlertDialog.Builder builderDelete = new AlertDialog.Builder(
MainActivity.this);
builderDelete
.setTitle(R.string.dialog_delete_all_title)
.setMessage(R.string.dialog_delete_all_content)
.setPositiveButton(R.string.dialog_delete_all_yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
FileHelper
.deleteAllRecords(currentActivity);
onResume();
dialog.cancel();
}
})
.setNegativeButton(R.string.dialog_delete_all_no,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
}).show();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
private void setSharedPreferences(boolean silentMode) {
....
}
@Override
protected Dialog onCreateDialog(int id) {
....... }
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
.....}
}
activity_main.xml
<item
android:id="@+id/menu_Enable_record"
android:enabled="false"
android:icon="@drawable/ic_record_enable"
android:orderInCategory="100"
android:title="@string/menu_Enable_record"/>
<item
android:id="@+id/menu_Disable_record"
android:enabled="false"
android:icon="@drawable/ic_record_disable"
android:orderInCategory="100"
android:title="@string/menu_Disable_record"/>
<item
android:id="@+id/menu_about"
android:icon="@drawable/ic_about"
android:orderInCategory="100"
android:title="@string/menu_about"/>
<item
android:id="@+id/menu_see_terms"
android:icon="@drawable/ic_menu_example"
android:orderInCategory="100"
android:title="@string/menu_terms"/>
<item
android:id="@+id/menu_privacy_policy"
android:icon="@drawable/ic_menu_example"
android:orderInCategory="100"
android:title="@string/menu_privacy_policy"/>
<item
android:id="@+id/menu_delete_all"
android:icon="@drawable/ic_delete_all"
android:orderInCategory="100"
android:title="@string/menu_delete_all"/>
style.xml
<style name="AppTheme" parent="android:Theme.Light" />
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
[这是主要的 activity,其中没有显示菜单项,操作栏太薄了,我应该怎么做才能显示菜单项]
主要活动
public class MainActivity extends Activity {
public ListView listView;
//public ScrollView mScrollView;
public ScrollView mScrollView2;
public TextView mTextView;
private static final int CATEGORY_DETAIL = 1;
private static final int NO_MEMORY_CARD = 2;
private static final int TERMS = 3;
public RadioButton radEnable;
public RadioButton radDisable;
private static Resources res;
private Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
res = getResources();
listView = (ListView) findViewById(R.id.mylist);
//mScrollView = (ScrollView) findViewById(R.id.ScrollView01);
mScrollView2 = (ScrollView) findViewById(R.id.ScrollView02);
mTextView = (TextView) findViewById(R.id.txtNoRecords);
SharedPreferences settings = this.getSharedPreferences(
Constants.LISTEN_ENABLED, 0);
boolean silentMode = settings.getBoolean("silentMode", true);
if (silentMode)
showDialog(CATEGORY_DETAIL);
context = this.getBaseContext();
// showDialog(TERMS);
}
@Override
protected void onResume() {
....
}
/**
* checks if an external memory card is available
*
* @return
*/
public static int updateExternalStorageState() {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
//return true;
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
SharedPreferences settings = this.getSharedPreferences(
Constants.LISTEN_ENABLED, 0);
boolean silentMode = settings.getBoolean("silentMode", true);
MenuItem menuDisableRecord = menu.findItem(R.id.menu_Disable_record);
MenuItem menuEnableRecord = menu.findItem(R.id.menu_Enable_record);
// silent is disabled, disableRecord item must be disabled
menuEnableRecord.setEnabled(silentMode);
menuDisableRecord.setEnabled(!silentMode);
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Toast toast;
final Activity currentActivity = this;
switch (item.getItemId()) {
case R.id.menu_about:
AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
builder.setTitle(R.string.about_title)
.setMessage(R.string.about_content)
.setPositiveButton(R.string.about_close_button,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
}).show();
break;
case R.id.menu_Disable_record:
setSharedPreferences(true);
toast = Toast.makeText(this,
this.getString(R.string.menu_record_is_now_disabled),
Toast.LENGTH_SHORT);
toast.show();
break;
case R.id.menu_Enable_record:
setSharedPreferences(false);
// activateNotification();
toast = Toast.makeText(this,
this.getString(R.string.menu_record_is_now_enabled),
Toast.LENGTH_SHORT);
toast.show();
break;
case R.id.menu_see_terms:
Intent i = new Intent(this.getBaseContext(), TermsActivity.class);
startActivity(i);
break;
case R.id.menu_privacy_policy:
Intent browserIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://www.privacychoice.org/policy/mobile?policy=306ef01761f300e3c30ccfc534babf6b"));
startActivity(browserIntent);
break;
case R.id.menu_delete_all:
AlertDialog.Builder builderDelete = new AlertDialog.Builder(
MainActivity.this);
builderDelete
.setTitle(R.string.dialog_delete_all_title)
.setMessage(R.string.dialog_delete_all_content)
.setPositiveButton(R.string.dialog_delete_all_yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
FileHelper
.deleteAllRecords(currentActivity);
onResume();
dialog.cancel();
}
})
.setNegativeButton(R.string.dialog_delete_all_no,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
}).show();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
private void setSharedPreferences(boolean silentMode) {
....
}
@Override
protected Dialog onCreateDialog(int id) {
....... }
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
.....}
}
activity_main.xml
<item
android:id="@+id/menu_Enable_record"
android:enabled="false"
android:icon="@drawable/ic_record_enable"
android:orderInCategory="100"
android:title="@string/menu_Enable_record"/>
<item
android:id="@+id/menu_Disable_record"
android:enabled="false"
android:icon="@drawable/ic_record_disable"
android:orderInCategory="100"
android:title="@string/menu_Disable_record"/>
<item
android:id="@+id/menu_about"
android:icon="@drawable/ic_about"
android:orderInCategory="100"
android:title="@string/menu_about"/>
<item
android:id="@+id/menu_see_terms"
android:icon="@drawable/ic_menu_example"
android:orderInCategory="100"
android:title="@string/menu_terms"/>
<item
android:id="@+id/menu_privacy_policy"
android:icon="@drawable/ic_menu_example"
android:orderInCategory="100"
android:title="@string/menu_privacy_policy"/>
<item
android:id="@+id/menu_delete_all"
android:icon="@drawable/ic_delete_all"
android:orderInCategory="100"
android:title="@string/menu_delete_all"/>
style.xml
<style name="AppTheme" parent="android:Theme.Light" />
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">