我能';t在android上运行非常简单的标签示例
大家好,我有这个问题。实际上,我需要在android应用程序上添加两个选项卡,我正在developer.android.com上阅读如何操作,但我无法运行该程序 以下是mi代码:我能';t在android上运行非常简单的标签示例,android,eclipse,Android,Eclipse,大家好,我有这个问题。实际上,我需要在android应用程序上添加两个选项卡,我正在developer.android.com上阅读如何操作,但我无法运行该程序 以下是mi代码: package com.example.example; import android.os.Bundle; import android.app.ActionBar; import android.app.Activity; import android.app.FragmentTransaction; impor
package com.example.example;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.app.ActionBar.Tab;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
};
// Add 3 tabs, specifying the tab's text and TabListener
for (int i = 0; i < 3; i++) {
actionBar.addTab(
actionBar.newTab()
.setText("Tab " + (i + 1))
.setTabListener(tabListener));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我认为问题出在manifest.xml中,因为当我尝试插入这两行时:
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS)
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
eclipse向我显示了一个错误:“minium sdk应该是11,而您的minium sdk应该是8”
然后我在manifest.xml中更改它,menssage错误会消失,但我无法在手机上运行它
这里是mi android_manifest.mxl:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.example.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
您应该使用
支持
库在运行低于API 11的SO版本的设备中使用操作栏
请看一下如何使用
要使用操作栏
,您应该调用:
final ActionBar actionBar = geSupportActionBar();
为了确保一切正常运行,您必须导入android.support.v7.app.ActionBar我添加了android.support.v4.app,但显示了一个错误“只能导入一个类型android.support.v4.app解析为一个包”支持
ActionBar
位于v7库中,而不是v4!好的,那么我有三个目录,其中有三个JAR要导入到项目1.-appcompat 2.-gridlayout 3.-mediarouter,我应该导入到我的项目中吗?我添加了appcompat及其解决方案,但我不能调用getSupportActionBar方法。
final ActionBar actionBar = geSupportActionBar();