該解決方案非常簡單。
你需要擴展「活動」類,在功能的onCreate到的setContentView你的基地XML佈局,也需要覆蓋的setContentView在基地活動課
例如:
1,創建「base_layout .xml「與下面的代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000"
android:padding="15dp" >
<LinearLayout android:orientation="horizontal" android:background="#000000"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:minHeight="50dp" android:paddingLeft="10dp">
<ImageView android:layout_width="wrap_content" android:id="@+id/ImageView01"
android:adjustViewBounds="true" android:layout_height="wrap_content"
android:scaleType="fitCenter" android:maxHeight="50dp" />
</LinearLayout>
<LinearLayout android:id="@+id/linBase"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</LinearLayout>
</LinearLayout>
2.創建」BaseActivity。Java」的
public class BaseActivity extends Activity {
ImageView image;
LinearLayout linBase;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.base_layout);
image = (ImageView)findViewById(R.id.ImageView01);
image.setImageResource(R.drawable.header);
linBase = (LinearLayout)findViewById(R.id.linBase);
}
@Override
public void setContentView(int id) {
LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(id, linBase);
}
}
和
public class SomeActivity extends BaseActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.some_layout);
//rest of code
}
}
我注意到,到目前爲止是請求進度條時(requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS)),這需要調用super.onCreate前需做的唯一的事情。我想這是因爲沒有任何東西可以又調用此函數之前繪製。
這爲我工作的偉大,希望你會發現自己的編碼這個有用。
感謝您的回覆,但標籤佈局不能解決我的問題。我想將我的徽標欄用作標題欄或標題欄,而不是像徽標欄上的每個圖標使用不同的選項卡。這應該使標題不是標籤的外觀。我正在開發我的應用程序使用android 2.1 –
謝謝AnDro。我認爲這是我想要的,它應該在我的應用程序中工作。 –