Android 如何将默认导航选项卡视图更改为自定义选项卡视图?
根据我的代码,我的默认导航选项卡如下所示 我的问题是:如何将上面的导航选项卡更改为下面附加的选项卡 我将如何实现这一点 我的SDK最低版本是8 我试了很多,但没有成功。有人能帮我吗Android 如何将默认导航选项卡视图更改为自定义选项卡视图?,android,navigationbar,Android,Navigationbar,根据我的代码,我的默认导航选项卡如下所示 我的问题是:如何将上面的导航选项卡更改为下面附加的选项卡 我将如何实现这一点 我的SDK最低版本是8 我试了很多,但没有成功。有人能帮我吗 谢谢。从 slidengtablayout.java SlidengAbstrip.java 然后创建xml文件 <com.emaple.ui.SlidingTabLayout android:id="@+id/sliding_tabs_home"
谢谢。从 slidengtablayout.java SlidengAbstrip.java 然后创建xml文件
<com.emaple.ui.SlidingTabLayout
android:id="@+id/sliding_tabs_home"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager_home"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white" />
SamplePagerAdapter.java
class SamplePagerAdapter扩展了PagerAdapter{
/**
*@返回要显示的页数
*/
@凌驾
public int getCount(){
返回10;
}
/**
*@return true,如果从{@link#instanceItem(ViewGroup,int)}返回的值是
*与添加到{@link ViewPager}的{@link View}相同的对象。
*/
@凌驾
公共布尔值isViewFromObject(视图,对象o){
返回o==视图;
}
/**
*返回{@code position}处项目的标题。这与此方法的作用一样重要
*返回是{@link SlidingTabLayout}中显示的内容。
*
*在这里,我们使用位置值构造一个,但对于实际应用,标题应该是
*参考项目的内容。
*/
@凌驾
公共字符序列getPageTitle(int位置){
返回“项目”+(位置+1);
}
/**
*实例化应显示在{@code position}的{@link View}
*从应用程序资源中展开布局,然后更改文本视图以表示位置。
*/
@凌驾
公共对象实例化项(视图组容器,int位置){
//利用我们的资源扩大新的布局
View=HomeActivity.this.GetLayoutFlater().inflate(R.layout.pager_项,
货柜(虚假);;
//将新创建的视图添加到ViewPager
container.addView(视图);
//从膨胀视图中检索TextView,并更新其文本
TextView title=(TextView)view.findViewById(R.id.item_title);
title.setText(String.valueOf(position+1));
Log.i(Log_标记,“实例化项()[position:+position+]”);
//返回视图
返回视图;
}
/**
*从{@link ViewPager}中销毁该项
*{@linkview}。
*/
@凌驾
公共项(视图组容器、int位置、对象){
container.removeView((视图)对象);
Log.i(Log_标签,“destroyItem()[位置:“+position+”]”);
}
}
我建议看一看
private void init() {
viewpagerHome.setAdapter(new SamplePagerAdapter());
slidingTabsHome.setViewPager(viewpagerHome);
}
class SamplePagerAdapter extends PagerAdapter {
/**
* @return the number of pages to display
*/
@Override
public int getCount() {
return 10;
}
/**
* @return true if the value returned from {@link #instantiateItem(ViewGroup, int)} is the
* same object as the {@link View} added to the {@link ViewPager}.
*/
@Override
public boolean isViewFromObject(View view, Object o) {
return o == view;
}
/**
* Return the title of the item at {@code position}. This is important as what this method
* returns is what is displayed in the {@link SlidingTabLayout}.
* <p/>
* Here we construct one using the position value, but for real application the title should
* refer to the item's contents.
*/
@Override
public CharSequence getPageTitle(int position) {
return "Item " + (position + 1);
}
/**
* Instantiate the {@link View} which should be displayed at {@code position}. Here we
* inflate a layout from the apps resources and then change the text view to signify the position.
*/
@Override
public Object instantiateItem(ViewGroup container, int position) {
// Inflate a new layout from our resources
View view = HomeActivity.this.getLayoutInflater().inflate(R.layout.pager_item,
container, false);
// Add the newly created View to the ViewPager
container.addView(view);
// Retrieve a TextView from the inflated View, and update it's text
TextView title = (TextView) view.findViewById(R.id.item_title);
title.setText(String.valueOf(position + 1));
Log.i(LOG_TAG, "instantiateItem() [position: " + position + "]");
// Return the View
return view;
}
/**
* Destroy the item from the {@link ViewPager}. In our case this is simply removing the
* {@link View}.
*/
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
Log.i(LOG_TAG, "destroyItem() [position: " + position + "]");
}
}