[英]Android Custom Title Bar Progress
我想在我的自定义标题栏中显示我当前所在的页面。
例如,我有10个页面,那么我将水平有10个点,标记的点是当前页面。
但是我不知道我该如何动态地做到这一点。
我想做这样的事情:将我的自定义RelativeLayout添加到标题栏
getWindow().setsetFeatureInt(Window.FEATURE_CUSTOM_TITLE, new CustomTitleBar(this));
我读了很多有关它的内容,但是我发现我应该使用xml文件来做。 但是我可以向该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。 为什么是这样!?
是的,您可以通过在xml文件中引用它们来将可绘制对象添加到xml文件中。
通过使用
@drawable/your_drawable
如果这是您要的..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.