Android 向现有应用程序添加支持操作栏:未显示菜单项
我用minSDK 14实现了一个应用程序,效果非常好。现在我正试图“降级”到minSDK 10,看看会发生什么 我已经修复了Android 向现有应用程序添加支持操作栏:未显示菜单项,android,android-actionbar,android-actionbar-compat,Android,Android Actionbar,Android Actionbar Compat,我用minSDK 14实现了一个应用程序,效果非常好。现在我正试图“降级”到minSDK 10,看看会发生什么 我已经修复了GridLayout和Switch之类的问题,但是ActionBar不再显示任何项目 我已将我的主要活动从FragmentActivity更改为ActionBarActivity。然后我将getActionBar()更改为getSupportActionBar()。在那之后,我将清单文件中的主题样式更改为几个东西,只是为了看看是否发生了什么事情。现在我被卡住了,有什么遗漏吗
GridLayout
和Switch
之类的问题,但是ActionBar
不再显示任何项目
我已将我的主要活动从FragmentActivity
更改为ActionBarActivity
。然后我将getActionBar()
更改为getSupportActionBar()
。在那之后,我将清单文件中的主题样式更改为几个东西,只是为了看看是否发生了什么事情。现在我被卡住了,有什么遗漏吗
public class MainActivity extends ActionBarActivity {
/** Called when the activity is first created. */
// private BluetoothAdapter mBluetoothAdapter = null;
public static String sAddress = "00:00:00:00:00:00"; // BoxAdresse
public AlertDialog.Builder b;
public BluetoothConnection bc = new BluetoothConnection();
// Debugging
private static final String TAG = "Main_Activity";
private static final boolean D = true;
// Message types sent from the BluetoothChatService Handler
public static final int MESSAGE_STATE_CHANGE = 1;
public static final int MESSAGE_READ = 2;
public static final int MESSAGE_WRITE = 3;
public static final int MESSAGE_DEVICE_NAME = 4;
public static final int MESSAGE_TOAST = 5;
public static final String TOAST = "toast";
// Key names received from the BluetoothChatService Handler
public static final String DEVICE_NAME = "device_name";
// Intent request codes
public static final int REQUEST_CONNECT_DEVICE_SECURE = 1;
private static final int REQUEST_ENABLE_BT = 3;
private static int CONNECT_COUNTER = 0;
private static final int MAX_CONNECT_ATTEMPT = 4;
private static final String TAG_ADMIN = "user_admin";
private static final String TAG_STANDARD = "user_standard";
private static String adminPermission;
// Name of the connected device
public static String mConnectedDeviceName = null;
// Local Bluetooth adapter
private static BluetoothAdapter mBluetoothAdapter = null;
// Member object for the chat services
public static BluetoothService mSerialService = null;
private static String mInStringBuffer;
public static Handler handler = new Handler(); // for postDelayed
private ActionBar actionBar;
public static Menu mMenu;
private Byte_Translation bWork;
public static FragmentActivity thisFragmentActivity = null;
private FragmentTabHost mTabHost;
private View tabIndicator1, tabIndicator2, tabIndicator3, tabIndicator4;
private TextView title;
private CharSequence mTitle;
String[] mFragments = {
"de.teamgrimm.android.crohmapp.tabs.InformationTabs",
"de.teamgrimm.android.crohmapp.tabs.DevelopmentTab",
"de.teamgrimm.android.crohmapp.tabs.ChargingTab" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bottom_tabs);
actionBar = getSupportActionBar();
mTitle = getTitle();
// set the Icon
actionBar.setIcon(R.drawable.ic_launcher);
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
tabIndicator1 = LayoutInflater.from(this).inflate(
R.layout.crohmapptheme_tab_indicator_holo,
mTabHost.getTabWidget(), false);
title = (TextView) tabIndicator1.findViewById(android.R.id.title);
title.setText("Home");
tabIndicator2 = LayoutInflater.from(this).inflate(
R.layout.crohmapptheme_tab_indicator_holo,
mTabHost.getTabWidget(), false);
title = (TextView) tabIndicator2.findViewById(android.R.id.title);
title.setText("Infos");
tabIndicator3 = LayoutInflater.from(this).inflate(
R.layout.crohmapptheme_tab_indicator_holo,
mTabHost.getTabWidget(), false);
title = (TextView) tabIndicator3.findViewById(android.R.id.title);
title.setText("Charging");
tabIndicator4 = LayoutInflater.from(this).inflate(
R.layout.crohmapptheme_tab_indicator_holo,
mTabHost.getTabWidget(), false);
title = (TextView) tabIndicator4.findViewById(android.R.id.title);
title.setText("Development");
mTabHost.addTab(
mTabHost.newTabSpec("home").setIndicator(tabIndicator1),
HomeFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("infos")
.setIndicator(tabIndicator2), InformationTabs.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("charging").setIndicator(tabIndicator3),
ChargingTabs.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("development").setIndicator(tabIndicator4),
DevelopmentTabs.class, null);
thisFragmentActivity = this;
bWork = new Byte_Translation(this, mHandler);
InOutFragment.mOutgoingArrayAdapter = new ArrayAdapter<String>(this,
R.layout.message);
InOutFragment.mIncomingArrayAdapter = new ArrayAdapter<String>(this,
R.layout.message);
ManualDebugFragment.mReceivedHexArrayAdapter = new ArrayAdapter<String>(
this, R.layout.message);
ManualDebugFragment.mSentHexArrayAdapter = new ArrayAdapter<String>(
this, R.layout.message);
DebugFragment.debugArrayAdapter = new ArrayAdapter<String>(this,
R.layout.message);
// // Get local Bluetooth adapter
// mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
//
// // If the adapter is null, then Bluetooth is not supported
// if (mBluetoothAdapter == null) {
//
// Toast.makeText(this, "Bluetooth is not available",
// Toast.LENGTH_LONG).show();
// finish();
// return;
// }
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// // Take appropriate action for each action item click
// if (menuItem.get_mItem(item.getItemId()) != null) {
// switch (menuItem.get_mItem(item.getItemId())) {
// Take appropriate action for each action item click
if (item != null) {
switch (item.getItemId()) {
case (R.id.connect_box):
if (!Byte_Translation.isConnected()) {
devicedialog();
} else {
if (mSerialService != null)
mSerialService.stop();
}
return true;
case (R.id.disconnect_box):
if (Byte_Translation.isConnected()) {
// Stop BT Service to disconnect
if (mSerialService != null)
mSerialService.stop();
sAddress = "00:00:00:00:00:00";
}
return true;
case (R.id.login_box):
Byte_Translation.LOGIN_SUCCESSFULL = false;
Byte_Translation.LOGINCOUNT = 0;
Byte_Translation.login();
return true;
case (R.id.refresh_menu):
Byte_Translation.refresh_all();
Byte_Translation.refresh_timer();
return true;
case (R.id.auto_refresh):
if (!Byte_Translation.AUTOREFRESH) {
Byte_Translation.AUTOREFRESH = true;
item.setChecked(true);
Byte_Translation.refresh();
} else {
Byte_Translation.AUTOREFRESH = false;
item.setChecked(false);
}
save_shared_Prefs();
return true;
case (android.R.id.home):
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
MainActivity.this);
alertDialogBuilder.setTitle("Exit " + this.getTitle());
alertDialogBuilder.setMessage("Are you sure?");
// set positive button: Yes message
alertDialogBuilder.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
onBackPressed();
}
});
// set negative button: No message
alertDialogBuilder.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
// show alert
alertDialog.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
return false;
}
公共类MainActivity扩展了ActionBarActivity{
/**在首次创建活动时调用*/
//私有BluetoothAdapter mBluetoothAdapter=null;
公共静态字符串sAddress=“00:00:00:00:00:00”;//BOXADRESS
公共AlertDialog.Builder b;
公共BluetoothConnection bc=新BluetoothConnection();
//调试
私有静态最终字符串TAG=“Main\u活动”;
私有静态最终布尔值D=true;
//从BluetoothChatService处理程序发送的消息类型
公共静态最终int消息_STATE_CHANGE=1;
公共静态最终int消息_READ=2;
公共静态最终int消息_WRITE=3;
公共静态最终int消息\u设备\u名称=4;
公共静态最终int消息_TOAST=5;
公共静态最终字符串TOAST=“TOAST”;
//从BluetoothChatService处理程序接收的密钥名称
公共静态最终字符串DEVICE\u NAME=“DEVICE\u NAME”;
//意图请求代码
公共静态最终int请求\u连接\u设备\u安全=1;
私有静态最终整数请求_ENABLE_BT=3;
专用静态int CONNECT_计数器=0;
专用静态最终int最大连接尝试=4;
私有静态最终字符串标记\u ADMIN=“user\u ADMIN”;
私有静态最终字符串标记\u STANDARD=“user\u STANDARD”;
私有静态字符串管理权限;
//连接的设备的名称
公共静态字符串mConnectedDeviceName=null;
//本地蓝牙适配器
私有静态BluetoothAdapter mBluetoothAdapter=null;
//聊天室服务的成员对象
公共静态BluetoothService mSerialService=null;
私有静态字符串mInStringBuffer;
public static Handler=new Handler();//用于postDelayed
私人ActionBar ActionBar;
公共静态菜单;
专用字节转换b工作;
公共静态碎片活动thisFragmentActivity=null;
私有碎片选项卡主机mTabHost;
私有视图选项卡Indicator 1、选项卡Indicator 2、选项卡Indicator 3、选项卡Indicator 4;
私有文本视图标题;
私有字符序列mTitle;
字符串[]MFFragments={
“de.teamgrimm.android.crohmapp.tabs.InformationTabs”,
“de.teamgrimm.android.crohmapp.tabs.DevelopmentTab”,
“de.teamgrimm.android.crohmapp.tabs.ChargingTab”};
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.bottom_选项卡);
actionBar=getSupportActionBar();
mTitle=getTitle();
//设置图标
actionBar.setIcon(R.drawable.ic_启动器);
mTabHost=(FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(这个,getSupportFragmentManager(),R.id.realtabcontent);
tabIndicator1=从(此)开始放平。充气(
R.layout.crohmapptheme\u选项卡\u指示器\u全息图,
mTabHost.getTabWidget(),false);
title=(TextView)选项卡indicator1.findviewbyd(android.R.id.title);
标题:setText(“主页”);
tabIndicator2=从(此)开始放平。充气(
R.layout.crohmapptheme\u选项卡\u指示器\u全息图,
mTabHost.getTabWidget(),false);
title=(TextView)选项卡indicator2.findViewById(android.R.id.title);
title.setText(“信息”);
tabIndicator3=从(此)开始放平。充气(
R.layout.crohmapptheme\u选项卡\u指示器\u全息图,
mTabHost.getTabWidget(),false);
title=(TextView)选项卡indicator3.findviewbyd(android.R.id.title);
title.setText(“收费”);
tabIndicator4=从(此)开始放平。充气(
R.layout.crohmapptheme\u选项卡\u指示器\u全息图,
mTabHost.getTabWidget(),false);
title=(TextView)选项卡indicator4.findviewbyd(android.R.id.title);
标题:setText(“开发”);
mTabHost.addTab(
mTabHost.newTabSpec(“主”)设置指示器(tabIndicator1),
HomeFragment.class,null);
mTabHost.addTab(mTabHost.newTabSpec(“信息”)
.setIndicator(tabIndicator2),InformationTabs.class,null);
mTabHost.addTab(
mTabHost.newTabSpec(“充电”).设置指示器(tabIndicator3),
ChargingTabs.class,空);
mTabHost.addTab(
mTabHost.newTabSpec(“开发”).setIndicator(tabIndicator4),
DevelopmentTabs.class,空);
thisFragmentActivity=此;
bWork=新的字节转换(这是mHandler);
InOutFragment.mOutgoingArrayAdapter=新阵列适配器(此,
R.layout.message);
InOutFragment.mIncomingArrayAdapter=新的ArrayAdapter(此,
R.layout.message);
ManualDebugFragment.mrReceiveDhexarrayAdapter=新阵列适配器(
这个,R.layout.message);
ManualDebugFragment.mSentHexArrayAdapter=新的ArrayAdapter(
这个,R.layout.message);
DebugFragment.debugArrayAdapter=新的ArrayAdapter(此,
R.layout.message);
////获取本地蓝牙适配器
//mBluetoothAdapter=BluetoothAdapter.getDefaultAdapter();
//
////如果适配器为空,则不支持蓝牙
//if(mBluetoothAdapter==null){
//
//Toast.makeText(此“蓝牙不可用”,
//Toast.LENGTH_LONG).show();
//完成();
//返回;
// }
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
////为每个操作项执行适当的操作单击
//if(menuItem.get_-mItem(item.getItemId())!=null){
//开关(menuItem.get\u mItem(item.getItemId())){
//对每个操作项采取适当的操作单击
如果(项!=null){
开关(ite)
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
}