0

我想将操作栏添加到具有此主题的应用程序(@android:style/Theme.Black.NoTitleBar)。如果您按住最近的应用程序按钮,这些菜单项在手机中可见,但如果是平板电脑则无法正常工作。我试过但我没有。请任何人都可以帮助我。

code


/**
 * The purpose of this Activity is to manage the activities in a tab.
 * Note: Child Activities can handle Key Presses before they are seen here.
 * @author Eric Harlow
 */
public class TabGroupActivity extends ActivityGroup {


   ..................
   ..............

  public boolean onCreateOptionsMenu(Menu menu){
    // TODO Auto-generated method stub      
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.app_menu, menu);
    return true;
}

  public boolean onOptionsItemSelected(MenuItem item){      
    // TODO Auto-generated method stub
    switch (item.getItemId()) {             
        case R.id.AppExit:  
            showDialog(DIALOG_exitbtnalert);
            break; 
        case R.id.AppLogout:    
            showDialog(DIALOG_logoutbtnalert);
            break; 
    }
    return super.onOptionsItemSelected(item);
} 

  //Alert dialog for Exit and Logout
  protected Dialog onCreateDialog(int id) 
  {
      switch (id)
  { 
  case DIALOG_exitbtnalert:
      return new AlertDialog.Builder(getParent())            
      .setTitle("MyMedPix247 Alert")
      .setMessage("Are you sure you want to Exit from the App?")
      .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton)
          {
              DH_Constant.blnAppExit = true;
              finish();
          }
      })
      .setNegativeButton("No", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton)
          {               
              dialog.dismiss();
          }
      })
      .create(); 

  case DIALOG_logoutbtnalert:
      return new AlertDialog.Builder(getParent())            
      .setTitle("MyMedPix247 Alert")
      .setMessage("Are you sure you want to Logout?")
      .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton)
          {
              DH_Constant.blnApplogout = true;
              finish();
          }
      })
      .setNegativeButton("No", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) 
          {               
              dialog.dismiss();
          }
      })
      .create();                      
  }
  return null;
  }
 ................
 .................
}

显现

< ?xml version="1.0" encoding="utf-8"?>
< manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.ibkr.dicomhub"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="11"/>

<application 
    android:icon="@drawable/dhapp_icon" 
    android:label="@string/app_name"
    android:debuggable="true"
    android:name="MyApplication"
    android:theme="@android:style/Theme.Black.NoTitleBar">
    <activity android:name=".DH_Home" android:windowSoftInputMode="stateHidden"
              android:label="@string/app_name" android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>        
</application>
< /manifest>

菜单

    < ?xml version="1.0" encoding="utf-8"?>
    < menu  xmlns:android="http://schemas.android.com/apk/res/android">

  < item android:id="@+id/AppExit"
    android:title="Exit"  
    android:showAsAction="ifRoom|withText"
    android:icon="@drawable/exit_icon" />

  < item android:id="@+id/AppLogout"
    android:title="Logout"
    android:showAsAction="ifRoom|withText"
    android:icon="@drawable/logout_icon" />
< /menu>
4

2 回答 2

1

我想将操作栏添加到具有此主题的应用程序(@android:style/Theme.Black.NoTitleBar)。

根据定义,这是不可能的。请切换到Theme.Black而不是Theme.Black.NoTitleBar.

于 2012-11-05T11:48:25.550 回答
0

操作栏仅适用于 .holo 主题。所以考虑使用@android:style/Theme.Holo.Light.DarkActionBar

于 2013-10-22T12:24:42.980 回答