标签: android-tablayout

如何在TabLayout中的Tabs上显示未读通知计数器?

我正在使用android支持设计库的TabLayout.

我想在标签上显示未读通知计数器,标题如下图所示.

在此输入图像描述

如何在Tab里面设置未读数TabLayout

tabs android android-tabs android-design-library android-tablayout

6
推荐指数
1
解决办法
6660
查看次数

更改viewPager滑动方向

我正在使用TabLayout和viewPager,并选择向左或向右滑动viewPager以便在页面之间导航.

我的问题是,我的应用程序是基于RTL(从右到左),滑动方向是相反的.

我正在尝试将滑动方向从默认更改为反转版本.我一直在网上搜索很多,但找不到怎样的方法.

我正在使用 android.support.v4.view.ViewPager;

这就是我用viewPager初始化我的TabLayout的方法:

// View Page Adapter
        final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
        final PagerAdapter adapter = new PagerAdapter
                (getSupportFragmentManager(), tabLayout.getTabCount());
        //View Page Adapter Configuration
        viewPager.setAdapter(adapter);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        viewPager.setOffscreenPageLimit(3);
        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewPager.setCurrentItem(tab.getPosition());
            }
Run Code Online (Sandbox Code Playgroud)

简介:目前,当我向左滑动viewPager时,它会显示下一页.在RTL中,当您向右滑动viewPager时,它会显示下一页.

这可能很难理解,但在这里. 向右滑动即可显示下一页

向右滑动即可显示下一页

我需要向右滑动以显示上一页.

android android-viewpager android-tablayout

6
推荐指数
3
解决办法
9820
查看次数

使用Backstack时TabLayout ViewPager不加载

我在我的一个片段中使用TabLayout,并使用viewPager在标签下方的两个片段之间切换.

当我单击其中一个较低片段中的FAB时,我加载一个新片段(用于输入).

但是 - 当我按下BACK按钮时,TabLayout会显示但没有任何一个较低的片段(由页面表示).

那么我做错了什么?

  • 是否有更好的方式来交换片段
  • 有没有办法按后退按钮并返回正在显示的viewPager页面?

在FAB点击之前来自BackStack 使用TabLayout的片段:CustomTemplatesFragment

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view =  inflater.inflate(R.layout.fragment_custom_templates, container, false);
    final TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
    tabLayout.addTab(tabLayout.newTab().setText(R.string.macro_tab));
    tabLayout.addTab(tabLayout.newTab().setText(R.string.lifestyle_tab));
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    final ViewPager viewPager = (ViewPager) view.findViewById(R.id.pager);
    final CustomTemplatesPagerAdapter adapter = new CustomTemplatesPagerAdapter
            (getFragmentManager(), tabLayout.getTabCount());
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {

        }

        @Override
        public void …
Run Code Online (Sandbox Code Playgroud)

android android-fragments back-stack fragment-backstack android-tablayout

6
推荐指数
1
解决办法
2864
查看次数

TabLayout中的片段仅在用户滑动Android时加载

嗨,我正在使用和制作一个带有A fragment和少数孩子的应用程序.问题是我的孩子(从)总是执行(每当用户点击父母时加载所有代码.如何让孩子只在用户滑动时加载(例如我有2个标签,仅在标签2中的内容)用户滑动到标签2时加载fragmenttablayoutviewpagerfragmentTablayoutfragmentfragment

这是我的父fragment代码

public class ManageEventFragment extends Fragment {


    public ManageEventFragment() {
        // Required empty public constructor
    }


    TabLayout tabLayout;
    ViewPager viewPager;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View viewFragment = inflater.inflate(R.layout.fragment_manage_event, container, false);

        viewPager = (ViewPager) viewFragment.findViewById(R.id.viewPager);

        tabLayout = (TabLayout) viewFragment.findViewById(R.id.tabLayout);

        viewPager.setAdapter(new CustomAdapter(getChildFragmentManager(), getContext()));
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));

        return viewFragment;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {

        //        tabLayout.setupWithViewPager(viewPager);
        tabLayout.post(new Runnable() {
            @Override
            public void run() { …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-viewpager android-tablayout

6
推荐指数
1
解决办法
1万
查看次数

Android工具栏在CollapsingToolbarLayout中重叠TabLayout

我试图让CollapsingToolbarLayoutToolbarTabLayout它下面的,但他们相互重叠,我得到这个

在此输入图像描述

我尝试了很多解决方案,但仍然有这个问题.这是我的xml:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/colorAppPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <RelativeLayout
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:background="@drawable/material_plane"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/header_png"
                app:layout_collapseMode="parallax"
                app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">

                <ImageView
                    android:id="@+id/imageViewPhoto"
                    android:layout_width="80dp"
                    android:layout_height="80dp"
                    android:layout_centerInParent="true" />

                <TextView
                    android:id="@+id/textViewName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="false"
                    android:layout_below="@+id/imageViewPhoto"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:text="TEXT"
                    android:textColor="@color/white"
                    android:textSize="16dp" />
            </RelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:fitsSystemWindows="true"
                android:gravity="top"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|enterAlways">

                <TextView
                    android:id="@+id/toolbar_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:textColor="@color/white"
                    android:textSize="20dp"
                    android:textStyle="bold" />
            </android.support.v7.widget.Toolbar>

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs" …
Run Code Online (Sandbox Code Playgroud)

android overlapping android-toolbar android-coordinatorlayout android-tablayout

6
推荐指数
1
解决办法
3648
查看次数

将选项卡布局中的图标对齐到左侧

您好我在我的活动中创建了一个标签布局.这是主要的.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/main_layout"
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.xxxxxx.eventmanager.EventDetailsActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/toolbarContainer"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:background="?attr/colorPrimary"
            android:elevation="6dp"
            android:minHeight="?attr/actionBarSize"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbarContainer"
        android:background="?attr/colorPrimary"
        android:elevation="6dp"
        android:minHeight="?attr/actionBarSize"
        app:tabTextColor="@color/colorLight"
        app:tabSelectedTextColor="@color/colorAccent"
        android:textAlignment=""
        android:theme="@style/AppTheme"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/tab_layout"/>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的.java类:

package com.xxxxxx.eventmanager;

import android.graphics.drawable.Drawable;
import android.support.design.widget.TabLayout;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.xxxxxx.eventmanager.adapters.EventPagerAdapter;

public class EventDetailsActivity extends AppCompatActivity  {

    /** …
Run Code Online (Sandbox Code Playgroud)

android android-tablayout

6
推荐指数
2
解决办法
7775
查看次数

选择选项卡时如何在选项卡布局中为项目设置动画?

我想在我选择标签图标时想要图像旋转动画的标签时放置动画.下面是示例,但它在iOS中.

在此输入图像描述

animation android tabwidget android-tablayout

6
推荐指数
1
解决办法
3564
查看次数

TabLayout:为每个选项卡设置自定义颜色

我看到很多问题说明如何为选定(活动)和未选中(非活动)选项卡设置不同的颜色.我也知道谷歌提供void setTabTextColors (int normalColor, int selectedColor)了实现这一目标.

我的要求有点不同,我正在研究一个带有TabLayout和的测验应用程序CardView.TabLayout允许用户在问题之间导航并CardView用于显示问题.

我需要设置用户已选择答案的选项卡的颜色与用户尚未应答的选项卡的颜色不同.默认情况下,TextColor是黑色的,但如果用户选择了答案,那么tabcolor应该变为蓝色(仅适用于例如.)并且它应该保持这种状态直到用户退出.我有一个int名为的数组Select,它将保存用户选择的选项的值(值范围在1到4之间).在分配Select数组时,我也用-1初始化它.我想到设置一个循环,然后如果数组是-1保持选项卡原样或将tabcolor设置为蓝色.

我该如何实现此功能?

android android-tablayout

6
推荐指数
1
解决办法
3512
查看次数

如何使用tabContentStart从设备屏幕中间启动内容

我正在使用TabLayoutViewPager

<android.support.v4.view.ViewPager
        android:id="@+id/view_pager_social_profiles"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"></android.support.v4.view.ViewPager>

<android.support.design.widget.TabLayout
        android:id="@+id/tab_layout_social_profiles"
        android:layout_width="match_parent"
        android:layout_height="112dp"
        app:tabContentStart="72dp"
        app:tabGravity="center"
        app:tabIndicatorHeight="0dp"
        app:tabMode="scrollable"></android.support.design.widget.TabLayout>
Run Code Online (Sandbox Code Playgroud)

我想从屏幕中间开始选项卡内容,因此如果只有一个选项卡,它将与屏幕正中对齐(水平),并且所选选项卡将始终位于中心.

android android-layout android-viewpager android-tabs android-tablayout

6
推荐指数
1
解决办法
1403
查看次数

使用选项卡式片段单击另一个recyclerview片段的特定项目单击时加载recyclerview片段?

我检查了其他答案和文章.但找不到我要找的东西.我可能会遗漏一些东西.

我有一个标签式活动,其中包含三个片段:

  1. FragmentHome(表1),
  2. FragmentTwo(表2),
  3. FragmentThree(表3).

现在我想在单击HomeFragment的特定项目时加载另一个片段("FragmentAnother").说,我想在HomeFragment(Recyclerview片段)中单击"5th"项目时加载"FragmentAnother"(RecyclerViewFragment).我想在HomeFragment中为特定项加载特定的detailView.怎么做到这一点?

MainActivity.java

public class MainActivity extends AppCompatActivity {

private SectionsPagerAdapter mSectionsPagerAdapter;

private ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);

    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager)); …
Run Code Online (Sandbox Code Playgroud)

adapter android-fragments android-viewpager android-recyclerview android-tablayout

6
推荐指数
1
解决办法
510
查看次数