ActionBarSherlock-如何在布局中的每个xml文件上创建标题? [英] ActionBarSherlock - How does it creates title on each xml files in layout?

查看:87
本文介绍了ActionBarSherlock-如何在布局中的每个xml文件上创建标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我已成功在Eclipse中实现了ActionBarSherlock演示示例。但是有些事情我无法理解,该库如何仅使用LinearLayout在tab_navigation.xml中自动创建带有一个图标和文本 ActionBarSharelock演示的标头

 < 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>

这个库对我来说是新的,我很想知道这个库是如何创建的? / p>

我在目标api 15上创建了一个新的android项目,并将ActionBarSherlock库附加到了它。然后,当我将其与demo示例项目进行比较时,我的新android项目中缺少一些文件。这些文件在下面列出。

  1.pom.xml 
2.bin / classes.dex
3.bin / jarlist.cache
4.bin / resources.ap_

而且我得到了eclipse上我的活动文件中出现新错误 R无法解析为变量。



如果您对我的问题有任何了解,请分享您的观点。

解决方案

使用最简单的示例:

 公共类Simple扩展了SherlockActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
setTheme(SampleList.THEME); //用于样本
中的主题切换super.onCreate(savedInstanceState);
setContentView(R.layout.text);
((TextView)findViewById(R.id.text))。setText(R.string.simple_content);
}
}

所有您需要做的就是让您的活动继承一个



您可以使用 getSupportActionBar() SherlockActivity的方法,例如设置标题: getSupportActionBar()。setTitle(R.string.my_title);


Recently i have successfully implemented the ActionBarSherlock Demos sample in eclipse. But there is something that i am not able to understand it that how this library automatically creates the header with one icon and a text "ActionBarSharelock Demos" in tab_navigation.xml by using merely a LinearLayout

<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>

This library is new for me and i am so anxious to know, how this library creates it?

I created a new android project on target api 15 and attach the ActionBarSherlock library to it. then i found that there some of the files are missing from my new android project when i compared it to demos sample project of android. Those files are listed below.

1.pom.xml
2.bin/classes.dex
3.bin/jarlist.cache
4.bin/resources.ap_

Moreover i got a new error in my activity file on eclipse "R cannot be resolved to a variable."

If you know anything about my problem then please share your views.

解决方案

To use the simplest example:

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);
    }
}

All you have to do is let your activity inherit one of the Sherlock activites (e.g., SherlockActivity, SherlockFragmentActivity).

You can program the action bar by using the getSupportActionBar() method of the SherlockActivity, e.g. to set the title: getSupportActionBar().setTitle( R.string.my_title );

这篇关于ActionBarSherlock-如何在布局中的每个xml文件上创建标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆