Java Code Examples for android.support.design.widget.TabLayout#getTabCount()

The following examples show how to use android.support.design.widget.TabLayout#getTabCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaginationHelper.java    From ForPDA with GNU General Public License v3.0 6 votes vote down vote up
public void updatePagination(Pagination newPagination) {
    this.pagination = newPagination;
    for (TabLayout tabLayout : tabLayouts) {
        if (pagination.getAll() <= 1) {
            tabLayout.setVisibility(View.GONE);
            return;
        }
        tabLayout.setVisibility(View.VISIBLE);
        boolean prevDisabled = pagination.getCurrent() <= 1;
        boolean nextDisabled = pagination.getCurrent() == pagination.getAll();
        TabLayout.Tab tab;
        int tag;
        for (int i = 0; i < tabLayout.getTabCount(); i++) {
            tab = tabLayout.getTabAt(i);
            if (tab == null || tab.getTag() == null) return;
            tag = (Integer) tab.getTag();
            if ((tag) == TAG_SELECT) continue;
            if (tab.getIcon() != null) {
                if ((tag == TAG_FIRST || tag == TAG_PREV) ? prevDisabled : nextDisabled)
                    tab.getIcon().setColorFilter(colorFilter);
                else
                    tab.getIcon().clearColorFilter();
            }
        }
    }
}
 
Example 2
Source File: LibraryFragment.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
private void makTabsFixed(@NonNull TabLayout tabLayout) {
    ViewGroup slidingTabStrip = (ViewGroup) tabLayout.getChildAt(0);
    int tabCount = tabLayout.getTabCount();
    for (int i = 0; i < tabCount; i++) {
        View tab = slidingTabStrip.getChildAt(i);
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) tab.getLayoutParams();
        layoutParams.weight = 1;
        tab.setLayoutParams(layoutParams);
    }
}
 
Example 3
Source File: EditActivity.java    From homeassist with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit);

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        Crashlytics.log("group: " + bundle.getString("group", "empty"));
        mGroup = CommonUtil.inflate(bundle.getString("group"), Group.class);
        if (mGroup == null) {
            discardAndFinish();
            return;
        }
    } else {
        discardAndFinish();
        return;
    }

    mSharedPref = getAppController().getSharedPref();
    mProgressDialog = CommonUtil.getProgressDialog(this);
    mProgressDialog.setContent(getString(R.string.progress_saving));

    //Setup Toolbar
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle(getString(R.string.title_edit));
    }

    TabLayout mTabLayout = findViewById(R.id.tabs);
    mTabLayout.setSelectedTabIndicatorHeight(CommonUtil.pxFromDp(this, 4f));
    mTabLayout.addTab(mTabLayout.newTab().setText(mGroup.getFriendlyName()));
    if (mGroup.hasMdiIcon()) {
        int tabIndex = mTabLayout.getTabCount() - 1;
        TabLayout.Tab currentTab = mTabLayout.getTabAt(tabIndex);
        if (currentTab != null) {
            View tab = LayoutInflater.from(this).inflate(R.layout.custom_tab, mTabLayout, false);

            TextView mdiText = tab.findViewById(R.id.text_mdi);
            TextView nameText = tab.findViewById(R.id.text_name);
            mdiText.setText(MDIFont.getIcon(mGroup.attributes.icon));
            nameText.setText(mGroup.getFriendlyName());
            nameText.setVisibility(View.VISIBLE);
            currentTab.setCustomView(tab);
        }
    }

    //mDatabaseManager = DatabaseManager.getInstance(this);
    //getSupportLoaderManager().initLoader(1, null, this);

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showAddDialog();
        }
    });

    setupRecyclerView();
}
 
Example 4
Source File: GroupActivity.java    From homeassist with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit);

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        Crashlytics.log("group: " + bundle.getString("group", "empty"));
        mGroup = CommonUtil.inflate(bundle.getString("group"), Group.class);
    } else {
        finish();
        return;
    }

    mSharedPref = getAppController().getSharedPref();
    mProgressDialog = CommonUtil.getProgressDialog(this);
    mProgressDialog.setContent(getString(R.string.progress_saving));

    //Setup Toolbar
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle(getString(R.string.title_edit));
    }

    TabLayout mTabLayout = findViewById(R.id.tabs);
    mTabLayout.setSelectedTabIndicatorHeight(CommonUtil.pxFromDp(this, 4f));
    mTabLayout.addTab(mTabLayout.newTab().setText(mGroup.getFriendlyName()));
    if (mGroup.hasMdiIcon()) {
        int tabIndex = mTabLayout.getTabCount() - 1;
        TabLayout.Tab currentTab = mTabLayout.getTabAt(tabIndex);
        if (currentTab != null) {
            View tab = LayoutInflater.from(this).inflate(R.layout.custom_tab, mTabLayout, false);

            TextView mdiText = tab.findViewById(R.id.text_mdi);
            TextView nameText = tab.findViewById(R.id.text_name);
            mdiText.setText(MDIFont.getIcon(mGroup.attributes.icon));
            nameText.setText(mGroup.getFriendlyName());
            nameText.setVisibility(View.VISIBLE);
            currentTab.setCustomView(tab);
        }
    }

    //mDatabaseManager = DatabaseManager.getInstance(this);
    //getSupportLoaderManager().initLoader(1, null, this);
    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showAddDialog();
        }
    });
}
 
Example 5
Source File: CashOutFragment.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view =  inflater.inflate(R.layout.fragment_cash_out, container, false);

    ViewGroup rootView = view.findViewById(R.id.rootView);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        rootView.setBackgroundColor(Color.parseColor(WalletActivity.primaryColor));
    }
    appBar = view.findViewById(R.id.app_bar);
    appBar.setTitle(getString(isCashOut ? R.string.cash_out_paygear : R.string.charge_paygear));
    appBar.setToolBarBackgroundRes(R.drawable.app_bar_back_shape,true);
    appBar.getBack().getBackground().setColorFilter(new PorterDuffColorFilter(Color.parseColor(WalletActivity.primaryColor),PorterDuff.Mode.SRC_IN));
    appBar.showBack();

    TabLayout tabLayout = view.findViewById(R.id.tab_layout);
    mPager = view.findViewById(R.id.view_pager);
    mPagerAdapter = new WalletPagerAdapter(getChildFragmentManager());
    mPager.setAdapter(mPagerAdapter);
    tabLayout.setupWithViewPager(mPager);

    if (isCashOut) {
        mPager.setCurrentItem(1);
    }

    for (int i = 0; i < tabLayout.getTabCount(); i++) {
        TabLayout.Tab tab = tabLayout.getTabAt(i);
        if (tab != null) {
            TextView textView = new TextView(getContext());
            textView.setId(android.R.id.text1);
            textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            textView.setTextColor(Color.WHITE);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
            textView.setTypeface(Typefaces.get(getContext(), Typefaces.IRAN_YEKAN_REGULAR));

            tab.setCustomView(textView);
        }
    }

    return view;
}