Android ActionBarSherlock-它如何在布局中的每个xml文件上创建标题?
最近,我在eclipse中成功地实现了ActionBarSherlock演示示例。但有一点我无法理解,这个库如何仅通过使用LinearLayout在tab_navigation.xml中自动创建带有一个图标和一个文本“ActionBarSharelock Demos”的标题Android ActionBarSherlock-它如何在布局中的每个xml文件上创建标题?,android,actionbarsherlock,Android,Actionbarsherlock,最近,我在eclipse中成功地实现了ActionBarSherlock演示示例。但有一点我无法理解,这个库如何仅通过使用LinearLayout在tab_navigation.xml中自动创建带有一个图标和一个文本“ActionBarSharelock Demos”的标题 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_paren
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="20dip">
</LinearLayout>
此外,我在eclipse上的活动文件中发现了一个新错误“R不能解析为变量”
如果您知道我的问题,请分享您的看法。使用最简单的示例:
public class Simple extends SherlockActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(SampleList.THEME); //Used for theme switching in samples
super.onCreate(savedInstanceState);
setContentView(R.layout.text);
((TextView)findViewById(R.id.text)).setText(R.string.simple_content);
}
}
您所要做的就是让您的活动继承一个Sherlock活动(例如,SherlockActivity、SherlockFragmentActivity)
您可以使用SherlockActivity的
getSupportActionBar()
方法编程操作栏,例如设置标题:getSupportActionBar().setTitle(R.string.my_title)代码>活动通常与SherlockActivity一起继承。它没有添加到布局xml中。@我说过我在eclipse的设计视图中看到了tab_navigation.xml,并找到了它。我在emulator上没有看到这一点。简单地说,如果我在sherlock演示示例的layout directory中创建一个xml文件,那么在design视图中,我可以在新的xml文件中看到一个图块和一个图像。这是我的问题。我做了这件事,它非常简单。我说我在eclipse的设计视图中看到了tab_navigation.xml,并发现了这一点。我在emulator上没有看到这一点。简单地说,如果我在sherlock演示示例的layout directory中创建一个xml文件,那么在design视图中,我可以在新的xml文件中看到一个图块和一个图像。这是我的问题。
public class Simple extends SherlockActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(SampleList.THEME); //Used for theme switching in samples
super.onCreate(savedInstanceState);
setContentView(R.layout.text);
((TextView)findViewById(R.id.text)).setText(R.string.simple_content);
}
}