在操作栏中创建选项卡我是Android的绝对初学者。现在我开始学习android。我即将创建带有标签的操作栏。但是我的Android SDK版本太低。所以我尝试使用旧的方式创建使用ActionBarActivity标签的操作栏。我也想知道新旧方法。现在我这样做。无法使用ActionBarActivity
我的活动类
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar bar = getSupportActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
for(int i = 1;i<=3;i++){
ActionBar.Tab tab = bar.newTab();
tab.setText("Tab" + i);
bar.addTab(tab);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
但是当我运行我的应用程序。这是抛出错误。请问我的代码有什么问题?我该如何纠正它?
向我们展示了logcat的RROR – Virthuss
'ActionBarActivity'已被弃用。使用'AppCompactActivity'和'ToolBar'。 – Piyush
我也想知道旧的方式 –