我正在使用TabLayout和View Pager来显示多个标签.我想更改选定的标签指示器.我用过,app:tabIndicatorColor但颜色没有变化.它呈现出绿色.我已经读过,默认情况下tabIndicator颜色被设置为color/accent,但是绿色不是我的强调颜色.我的xml如下:
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/primary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabIndicatorColor="@android:color/white"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@color/primary_light"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="@layout/header_layout"
app:menu="@menu/menu_drawer"
/>
Run Code Online (Sandbox Code Playgroud)
我错过了什么?图片来源:http://imgur.com/uNcbviv
我正在使用viewPager和android.support.design.widget.TabLayout.我的xml是
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/home_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/custom_tab_layout_height"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<!-- tabs -->
<android.support.design.widget.TabLayout
android:id="@+id/home_tabs"
android:layout_width="match_parent"
android:layout_height="@dimen/custom_tab_layout_height"
android:layout_alignParentBottom="true"
app:tabGravity="fill"
android:background="@color/light_blue_low_opacity"
app:tabIndicatorHeight="0dp"
app:tabMode="fixed"
app:tabPaddingEnd="0dp"
app:tabPaddingStart="0dp"
app:tabSelectedTextColor="@color/light_green"
app:tabTextAppearance="@style/HomeTabsTextAppearance"
app:tabTextColor="@color/white" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我将viewPager设置如下
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.home_container);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setPagingEnabled(false);
mViewPager.setOffscreenPageLimit(5);
tabLayout = (TabLayout) findViewById(R.id.home_tabs);
tabLayout.setTabTextColors(ContextCompat.getColorStateList(this, R.color.color_home_tabs));
tabLayout.setupWithViewPager(mViewPager);
Run Code Online (Sandbox Code Playgroud)
我的tabListener是
tabLayout.setOnTabSelectedListener(
new TabLayout.ViewPagerOnTabSelectedListener(mViewPager) {
@Override
public void onTabSelected(TabLayout.Tab tab) {
super.onTabSelected(tab);
int position = tab.getPosition();
mViewPager.setCurrentItem(position);
String tab0TextUnSelected = "<font color='" + ContextCompat.getColor(getApplicationContext(), R.color.white) + "'> " + getResources().getString(R.string.home_tab1) + …Run Code Online (Sandbox Code Playgroud) 我正在尝试更改选项卡布局中所选选项卡的文本颜色。指示器颜色工作正常,但 tabSelectedTextColor 似乎不起作用。颜色保持白色。我正在使用支持库 22.2.1,我做错了什么?有没有替代方法来实现这一目标
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
app:tabIndicatorColor="#000000"
app:tabSelectedTextColor="#000000"
app:tabMode="scrollable" />
Run Code Online (Sandbox Code Playgroud) 我的Android技能有些生锈,我希望有人可以帮助我。我有一个TabLayout带有的ViewPager,可将Fragment带有不同数据的相同内容刷一次ListView。一切正常,但我遇到了问题。标签页眉文本隐藏的一部分Fragment,从而将第一个元素ListView隐藏在后面。我确实已经尝试找到解决此问题的方法,但是我没有,我敢肯定它一定是简单但没有解决方法。如果您需要更多信息,请询问。我有这个活动布局:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
这是活动代码:
public class ParadasActivity extends AppCompatActivity
implements LoaderManager.LoaderCallbacks<Cursor>{
...
@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
while (cursor.moveToNext()) {
Tab tab =tabLayout.newTab();
tabLayout.addTab(tab);
}
Run Code Online (Sandbox Code Playgroud)
片段代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { …Run Code Online (Sandbox Code Playgroud) 我已经研究过这个,但我找不到任何东西。
什么时候用tabMode:fixed,什么时候用tabMode:scrollable?它们之间有什么区别?其中哪一个是最佳实践?
当我开始一个新的选项卡式活动时,我有这个生成的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="eis1617.muellerkimmeyer.app.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我该如何更改它,标签栏将放在屏幕的底部?在TabLayout标签上我已经尝试添加android:layout_gravity ="bottom",但它没有改变任何东西.
我看到了这个堆栈溢出帖子,但它并没有帮助我理解我必须做什么。我了解如何从查询中增加计数器值的概念。
但我不明白我应该使用什么。我应该使用Notification notification;还是BadgeViewer badgeViewer;?我更喜欢一种不必导入库的方法。
我正在尝试找到一种方法来更改Tab Title选定时的文本大小。到现在还没有退出。希望可以有人帮帮我。
我的代码如下:
XML :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tab_layout"
app:tabSelectedTextColor="@android:color/holo_orange_dark"
app:tabTextAppearance="@style/textAppearance">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pager_view"/>
Run Code Online (Sandbox Code Playgroud)
用于 tabTextAppearance 的样式:
<style name="textAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textSize">18sp</item>
<item name="android:textStyle">bold</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我的适配器:
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
private final Resources resources;
private static final int num = 3;
public ViewPagerAdapter(FragmentManager fm, Resources resources) {
super(fm);
this.resources = resources;
}
@Override
public Fragment getItem(int position) {
Fragment fragment = null;
switch (position) {
case 0:
fragment …Run Code Online (Sandbox Code Playgroud) 如标题中所述,我遇到了问题。当我实现选项卡时,它们不显示内容,并且选项卡不平滑,完全类似于以下问题:
这样它们就可以停在中间,依此类推。
您认为我做错了什么?我附上显示它的片段代码:
public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_profile, container, false);
ButterKnife.bind(this,view);
tabLayout.addTab(tabLayout.newTab().setText(getResources().getString(R.string.news_feed)));
tabLayout.addTab(tabLayout.newTab().setText(getResources().getString(R.string.bio)));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
mPager.setAdapter(new PagerAdapter(getActivity().getSupportFragmentManager()));
tabLayout.setupWithViewPager(mPager);
return view;
}
Run Code Online (Sandbox Code Playgroud)
以及布局:
<FrameLayout 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="#FFFFFF"
tools:context="com.my.app.profileFragment">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_below="@id/main_profile_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary"
android:elevation="6dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<!--android:minHeight="?attr/actionBarSize"-->
<!--android:layout_below="@+id/toolbar"-->
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
怎么了 我真的找不到错误。
先感谢您!
你的
格热哥兹
我正在使用Android应用程序,因此我想在将屏幕旋转到横向模式时为底部导航选项卡设置全宽。
activit_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/Conslayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:animateLayoutChanges="true"
android:layoutMode="opticalBounds"
android:background="?android:attr/windowBackground"
app:itemBackground="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation"
app:itemIconTint="@color/color_selector"
app:itemTextColor="@color/color_selector" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
在此视图中,我想将底部导航选项卡设置为与屏幕上的“选项卡”布局一样完整。
谢谢。