gpt4 book ai didi

android - 如何向 TabActivity 添加水平滑动?

转载 作者:行者123 更新时间:2023-11-29 01:48:16 25 4
gpt4 key购买 nike

我在这里看到了一些类似的帖子,但我还没有找到任何答案。我想在我的选项卡 Activity 中添加滑动手势,以便我能够使用该手势更改选项卡。

这是我的代码:

public class Domiciliaria extends TabActivity 
{
@Override
public void onCreate(Bundle savedInstanceState)
{
//requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seleccion);

//ActionBar bar = getActionBar();
//bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#cd3b05")));

final TabHost tabHost = getTabHost();
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
setTabColor(tabHost);
}
}
);

// Tab for primera
TabSpec primeraspec = tabHost.newTabSpec("info 1");
primeraspec.setIndicator("Datos", getResources().getDrawable(R.drawable.primera));
Intent primeraIntent = new Intent(this, Parte_primera.class);
primeraspec.setContent(primeraIntent);

// Tab for segunda
TabSpec segundaspec = tabHost.newTabSpec("info 2");
segundaspec.setIndicator("Motivos", getResources().getDrawable(R.drawable.segunda));
Intent segundaIntent = new Intent(this, Parte_segunda.class);
segundaspec.setContent(segundaIntent);

// Tab for tercero
TabSpec tercerospec = tabHost.newTabSpec("info 3");
tercerospec.setIndicator("Examen", getResources().getDrawable(R.drawable.tercera));
Intent terceroIntent = new Intent(this, Parte_tercera.class);
tercerospec.setContent(terceroIntent);

// Tab for Cuarto
TabSpec cuartospec = tabHost.newTabSpec("info 4");
cuartospec.setIndicator("otro", getResources().getDrawable(R.drawable.cuarta));
Intent cuartoIntent = new Intent(this, Parte_cuarta.class);
cuartospec.setContent(cuartoIntent);

// Tab for Final
TabSpec finalspec = tabHost.newTabSpec("info 4");
finalspec.setIndicator("Final", getResources().getDrawable(R.drawable.pago));
Intent finalIntent = new Intent(this, Final.class);
finalspec.setContent(finalIntent);

// agregando TabSpec to TabHost
tabHost.addTab(primeraspec); // Adding photos tab
tabHost.addTab(segundaspec); // Adding songs tab
tabHost.addTab(tercerospec);
tabHost.addTab(cuartospec);
tabHost.addTab(finalspec);
tabHost.getTabWidget().setStripEnabled(true);
tabHost.getTabWidget().setRightStripDrawable(R.drawable.barra_mamei);
tabHost.getTabWidget().setLeftStripDrawable(R.drawable.barra_mamei);
setTabColor(tabHost);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.about:
startActivity(new Intent(this, About.class));
return true;
case R.id.help:
startActivity(new Intent(this, Help.class));
return true;
case R.id.CasoEspecial:
startActivity(new Intent(this, CasoEspecial.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
// respond to menu item selection
}

protected void setTabColor(TabHost tabHost) {
// TODO Auto-generated method stub
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) {
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#E04006")); //unselected
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#fbfbf3")); // selected
}
}

最佳答案

您可以使用带有 fragment 和 ActionBar 的 ViewPager 实现 TabSwipe。

如果您希望使用 Minimum API 11,以下链接将向您展示如何操作。从 API 11 开始,ActionBar 可以使用 fragment 在应用程序中创建选项卡。

如果你需要支持旧版本,你应该使用Support LibraryActionBarSherlock

Check out this Link as well

关于android - 如何向 TabActivity 添加水平滑动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20015182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com