Android自定义标题栏进度

时间:2012-01-18 13:53:42

标签: android android-layout

我想在我的自定义标题栏中显示我当前的页面。

例如我有10页,那么我将水平地有10个点,标记的点是当前页面。

但我不知道我怎么能动态地做到这一点。

我想做这样的事情:将自定义RelativeLayout添加到标题栏

getWindow().setsetFeatureInt(Window.FEATURE_CUSTOM_TITLE, new CustomTitleBar(this));

我读了很多关于它的东西,但我发现我应该用xml文件来做。 但我可以动态drawables添加到这个xml文件然后!?或者我该怎么做?

编辑:

我真的不明白.. 我现在用:

创建了一个xml布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/bar"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"> 

</RelativeLayout>

现在我想为它添加一些按钮......

private void setTitleBar() {
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 

        RelativeLayout rl = (RelativeLayout)findViewById(R.id.bar);
        rl.addView(new Button(this));
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);

    }

但是在rl.addView(new Button(this))中;我得到一个NullPointerException。 这是为什么!?

1 个答案:

答案 0 :(得分:0)

是的,您可以通过在xml文件中引用它们来将drawable添加到xml文件中。

使用

@drawable/your_drawable

如果这是你要问的......

相关问题