[英]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.