我正在尝试像 Iphone 一样实现 TabBar,并希望在 ListView 上显示信息,在选择城市后,我得到另一个包含与该城市相关的事物的列表,它会在新视图中打开,但是当我调用新视图时,它会丢失 TabBAr,只显示视图,我需要知道他们的任何方式 ** 要在下一个视图中显示信息,但无论什么活动正在进行,TABBAR 都应保持在底部 **
我得到了我的第一个选项卡(主页选项卡)的屏幕截图
我在哪里选择城市移动到下一个屏幕,TabBar 停留在底部,然后到下一个视图,然后到下一个,依此类推,直到我显示图片的最后一个屏幕截图。
但我不知道我应该如何在 Android 中做到这一点。
我应该如何在我的主页选项卡中的所有视图上显示 TabBar
到目前为止,我有这个代码:
TabHostProvider.java
import android.app.Activity;
public abstract class TabHostProvider {
public Activity context;
public TabHostProvider(Activity context){
this.context = context;
}
public abstract TabView getTabHost(String category);
}
[标签.java][2]
MyTabHostProvider.java
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
public class MyTabHostProvider extends TabHostProvider {
private Tab cityTab;
private Tab searchTab;
private Tab mapTab;
private Tab favouriteTab;
private Tab settingTab;
private TabView tabView;
private GradientDrawable gradientDrawable, transGradientDrawable;
public MyTabHostProvider(Activity context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public TabView getTabHost(String category) {
// TODO Auto-generated method stub
tabView = new TabView(context);
tabView.setOrientation(TabView.Orientation.BOTTOM);
tabView.setBackgroundID(R.drawable.tab_background_gradient);
gradientDrawable = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM,
new int[] {0xFFB2DA1D, 0xFF85A315});
gradientDrawable.setCornerRadius(0f);
gradientDrawable.setDither(true);
transGradientDrawable = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM,
new int[] {0x00000000, 0x00000000});
transGradientDrawable.setCornerRadius(0f);
transGradientDrawable.setDither(true);
cityTab = new Tab(context, category);
cityTab.setIcon(R.drawable.navbar_allnormal);
cityTab.setIconSelected(R.drawable.navbar_allselected);
cityTab.setBtnText("City");
cityTab.setBtnTextColor(Color.WHITE);
cityTab.setSelectedBtnTextColor(Color.BLACK);
cityTab.setBtnGradient(transGradientDrawable);
cityTab.setSelectedBtnGradient(gradientDrawable);
cityTab.setIntent(new Intent(context, CityActivity.class));
searchTab = new Tab(context, category);
searchTab.setIcon(R.drawable.navbar_picturenormal);
searchTab.setIconSelected(R.drawable.navbar_pictureselected);
searchTab.setBtnText("Search");
searchTab.setBtnTextColor(Color.WHITE);
searchTab.setSelectedBtnTextColor(Color.BLACK);
searchTab.setBtnGradient(transGradientDrawable);
searchTab.setSelectedBtnGradient(gradientDrawable);
searchTab.setIntent(new Intent(context, SearchActivity.class));
mapTab = new Tab(context, category);
mapTab.setIcon(R.drawable.navbar_filenormal);
mapTab.setIconSelected(R.drawable.navbar_fileselected);
mapTab.setBtnText("Map");
mapTab.setBtnTextColor(Color.WHITE);
mapTab.setSelectedBtnTextColor(Color.BLACK);
mapTab.setBtnGradient(transGradientDrawable);
mapTab.setSelectedBtnGradient(gradientDrawable);
mapTab.setIntent(new Intent(context, MapFragment.class));
favouriteTab = new Tab(context, category);
favouriteTab.setIcon(R.drawable.navbar_videonormal);
favouriteTab.setIconSelected(R.drawable.navbar_videoselected);
favouriteTab.setBtnText("Favourites");
favouriteTab.setBtnTextColor(Color.WHITE);
favouriteTab.setSelectedBtnTextColor(Color.BLACK);
favouriteTab.setBtnGradient(transGradientDrawable);
favouriteTab.setSelectedBtnGradient(gradientDrawable);
favouriteTab.setIntent(new Intent(context, FavouritesActivity.class));
settingTab = new Tab(context, category);
settingTab.setIcon(R.drawable.navbar_morenormal);
settingTab.setIconSelected(R.drawable.navbar_moreselected);
settingTab.setBtnText("Settings");
settingTab.setBtnTextColor(Color.WHITE);
settingTab.setSelectedBtnTextColor(Color.BLACK);
settingTab.setBtnGradient(transGradientDrawable);
settingTab.setSelectedBtnGradient(gradientDrawable);
settingTab.setIntent(new Intent(context, SettingsActivity.class));
tabView.addTab(cityTab);
tabView.addTab(searchTab);
tabView.addTab(mapTab);
tabView.addTab(favouriteTab);
tabView.addTab(settingTab);
return tabView;
}
}
CityActivity.java
public class CityActivity extends Activity {
private final String TAG = CityActivity.class.getSimpleName();
private ListView moreList = null;
private final String[] moreItems = { "Srinagar", "Gulmarg", "Pehlgam", "Jammu", "Leh",
"Patnitop"};
private TextView tv;
private Button action_button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHostProvider tabProvider = new MyTabHostProvider(CityActivity.this);
TabView tabView = tabProvider.getTabHost("City");
tabView.setCurrentView(R.layout.city);
setContentView(tabView.render(0));
moreList = (ListView) findViewById(R.id.moreactivity_list);
moreList.setAdapter(new MoreCityAdapter(CityActivity.this, moreItems));
moreList.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
final String activity = moreList.getAdapter().getItem(position).toString().trim();
Log.d(TAG, "Clicked Item: " + activity);
tv = (TextView)findViewById(R.id.tv_header_title);
tv.setText(activity);
Intent intent = new Intent(CityActivity.this, Second.class);
startActivity(intent);
}
});
}
二.java
public class Second extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.city_second);
Here i need to show the Tab bar with my List View
How should i get the Tab Bar here and on my following Third,Fourth & Fifth Activity
}
}
[MoreCityAdapter.java][3]