我设计了一个用于选项卡(自定义全局活动)的活动,此活动有不同的按钮,如选项卡和单击按钮调用相应的活动,所以如果我调用 A(假设)活动,然后调用 B(假设)活动并返回 A,在这种情况下,再次创建活动。我希望此活动的行为应该像tabwidget
并从 开始onResume()
。这是否可能,如果是,那么请如何建议我。Thanks
全局选项卡布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1a1a1a"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="100" >
<ImageView
android:id="@+id/liveTV"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="20"
android:padding="5dp"
android:src="@drawable/tab_livetv_selector" />
<ImageView
android:id="@+id/movies"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="20"
android:padding="5dp"
android:src="@drawable/tab_movie_selector" />
<ImageView
android:id="@+id/vod"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="20"
android:padding="5dp"
android:src="@drawable/tab_vod_selector" />
<ImageView
android:id="@+id/events"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="20"
android:padding="5dp"
android:src="@drawable/tab_event_selector" />
<ImageView
android:id="@+id/playlist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="20"
android:padding="5dp"
android:src="@drawable/tab_playlist_selector" />
</LinearLayout>
全局选项卡的 Java 代码
public class Header extends LinearLayout implements OnClickListener {
private Context mContext;
private ImageView liveTV;
private ImageView movies;
private ImageView vod;
private ImageView events;
private ImageView playlist;
public static String tab = null;
public static boolean destroy = false;
public Header(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li;
li = (LayoutInflater) getContext().getSystemService(infService);
li.inflate(R.layout.header, this, true);
liveTV = (ImageView) findViewById(R.id.liveTV);
movies = (ImageView) findViewById(R.id.movies);
vod = (ImageView) findViewById(R.id.vod);
events = (ImageView) findViewById(R.id.events);
playlist = (ImageView) findViewById(R.id.playlist);
liveTV.setOnClickListener(this);
movies.setOnClickListener(this);
vod.setOnClickListener(this);
events.setOnClickListener(this);
playlist.setOnClickListener(this);
}
public void init() {
// setting selector for selected tab
if (tab.equals("movies")) {
destroy = true;
movies.setSelected(true);
liveTV.setSelected(false);
vod.setSelected(false);
events.setSelected(false);
playlist.setSelected(false);
} else if (tab.equals("vod")) {
destroy = true;
vod.setSelected(true);
liveTV.setSelected(false);
movies.setSelected(false);
events.setSelected(false);
playlist.setSelected(false);
} else if (tab.equals("events")) {
destroy = true;
events.setSelected(true);
liveTV.setSelected(false);
movies.setSelected(false);
vod.setSelected(false);
playlist.setSelected(false);
} else if (tab.equals("playlist")) {
destroy = true;
playlist.setSelected(true);
liveTV.setSelected(false);
movies.setSelected(false);
vod.setSelected(false);
events.setSelected(false);
} else {
destroy = true;
liveTV.setSelected(true);
movies.setSelected(false);
vod.setSelected(false);
events.setSelected(false);
playlist.setSelected(false);
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
//have to put here code for click
}
}
}
然后只需要像另一个视图一样将以下代码放在 xml 中
<com.media.ui.Header
android:id="@+id/layoutHeader"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom" />