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

The following examples show how to use android.support.design.widget.TabLayout#setSelectedTabIndicatorColor() . 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: MainActivity.java    From IdeaTrackerPlus with MIT License 6 votes vote down vote up
private void changeSecondaryColor() {

        //disable search mode for tabLayout
        disableSearchMode();

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

        tabLayout.setSelectedTabIndicatorColor(mSecondaryColor);
        mFab.setBackgroundTintList(ColorStateList.valueOf(mSecondaryColor));

        if (rightDrawer != null) {
            mColorItem2.withIconColor(mSecondaryColor);
            rightDrawer.updateItem(mColorItem2);
        }

        RecyclerOnClickListener.setSecondaryColor(mSecondaryColor);
    }
 
Example 2
Source File: MainActivity.java    From RetrofitClient with MIT License 6 votes vote down vote up
private void initView() {
        tlMain = (TabLayout) findViewById(R.id.tl_main);
        vpMain = (ViewPager) findViewById(R.id.vp_main);

        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(BaseRequestFragment.newInstance());
        fragmentList.add(FileUploadFragment.newInstance());
        fragmentList.add(FileDownloadFragment.newInstance());
        fragmentList.add(MovieDemoFragment.newInstance());
        String[] titles = {"基本请求", "文件上传","文件下载","电影Demo"};
        MainVpAdapter adapter = new MainVpAdapter(getSupportFragmentManager(), fragmentList, titles);
        vpMain.setAdapter(adapter);
//        vpReportIncomeSetting.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tlReportIncomeSetting));

        tlMain.setupWithViewPager(vpMain);
        tlMain.setTabMode(TabLayout.MODE_SCROLLABLE);
        tlMain.setTabTextColors(getResources().getColor(R.color.white), getResources().getColor(R.color.colorAccent));
        tlMain.setSelectedTabIndicatorColor(getResources().getColor(R.color.colorAccent));
    }
 
Example 3
Source File: ProgressChartCard.java    From ResearchStack with Apache License 2.0 6 votes vote down vote up
private void initializeViews() {
    titleTextView = (TextView) findViewById(R.id.view_chart_progress_title);
    titleTextView.setText(titleText);
    titleTextView.setTextColor(titleTextColor);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize);
    titleTextView.setTypeface(Typeface.create(titleTextTypeface, Typeface.NORMAL));

    finishView = (TextView) findViewById(R.id.view_chart_progress_finish);
    finishView.setText(finishText);
    finishView.setTextColor(finishTextColor);

    tabLayout = (TabLayout) findViewById(R.id.view_chart_progress_tabs);
    tabLayout.setSelectedTabIndicatorColor(tabIndicatorColor);
    tabLayout.setTabTextColors(tabTextColor, tabSelectedTextColor);

    chart = (PieChart) findViewById(R.id.view_chart_progress_chart);
    chart.setDrawSliceText(false);
    chart.setTouchEnabled(false);
    chart.setHoleColor(Color.TRANSPARENT);
    chart.setHoleRadius(95f);
    chart.getLegend().setEnabled(false);
    chart.setDescription("");
    chart.setCenterTextColor(centerTextColor);
    chart.setCenterTextSize(centerTextSize);
    chart.setCenterTextTypeface(Typeface.create(centerTextTypeface, Typeface.NORMAL));
}
 
Example 4
Source File: ColorPrefUtil.java    From ColorPrefUtil with MIT License 5 votes vote down vote up
/**
 *  Change icon tint and text colors of NavigationView
 *
 *  @param backgroundColorId is the color TabLayout's background
 *  @param tabNormalTextColorId is the normal text color
 *  @param tabSelectedTextColorId is the selected tab text color
 */
public static void changeColorOfTabLayout(@NonNull Context context, @NonNull TabLayout tabLayout, @NonNull Integer backgroundColorId,
                                   @NonNull Integer tabNormalTextColorId,
                                   @NonNull Integer tabSelectedTextColorId,
                                   @NonNull Integer tabSelectedIndicatorColorId){
    tabLayout.setBackgroundColor(ContextCompat.getColor(context, backgroundColorId));
    tabLayout.setTabTextColors(ContextCompat.getColor(context, tabNormalTextColorId), ContextCompat.getColor(context, tabSelectedTextColorId));
    tabLayout.setSelectedTabIndicatorColor(ContextCompat.getColor(context, tabSelectedIndicatorColorId));
}
 
Example 5
Source File: MainActivity.java    From android-news-app with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.app_name));
    setSupportActionBar(toolbar);

    // Find the view pager that will allow the user to swipe between fragments
    ViewPager viewPager = findViewById(R.id.viewpager);

    // Give the TabLayout the ViewPager
    TabLayout tabLayout = findViewById(R.id.sliding_tabs);

    tabLayout.setSelectedTabIndicatorColor(ContextCompat.getColor(this, R.color.colorAccent));
    tabLayout.setTabTextColors(
            ContextCompat.getColor(this, android.R.color.white),
            ContextCompat.getColor(this, android.R.color.black)
    );
    tabLayout.setupWithViewPager(viewPager);

    // Create an adapter that knows which fragment should be shown on each page
    NewsCategoryAdapter adapter = new NewsCategoryAdapter(this, getSupportFragmentManager());

    // Set the adapter onto the view pager
    viewPager.setAdapter(adapter);
}
 
Example 6
Source File: MainActivity.java    From Bookster with Apache License 2.0 5 votes vote down vote up
private void initView() {
    getWindow().setBackgroundDrawable(null);
    addpage(new AiXiaFragment(), "爱下");
    addpage(new ZhiXuanFragment(), "知轩藏书");
    addpage(new ZhouDuFragment(), "周读");
    addpage(new ShuYuZheFragment(), "书语者");
    addpage(new DongManZhiJiaFragment(), "动漫之家");
    addpage(new M360DFragment(), "360℃");
    addpage(new XiaoShuWuFragment(), "我的小书屋");
    addpage(new QiShuFragment(), "奇书");
    addpage(new BlahFragment(), "blah");

    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
    mPagerAdapter = new PagerAdapter(getSupportFragmentManager(), fragments, titles);
    viewPager.setAdapter(mPagerAdapter);
    viewPager.setOffscreenPageLimit(fragments.size());
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            searchView.findFocus();
            mPagerAdapter.setTop(tabLayout.getSelectedTabPosition());
        }
    });

    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("dark_theme", false)) {
        tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.DarkColor));
        tabLayout.setTabTextColors(tabLayout.getTabTextColors().getDefaultColor(), getResources().getColor(R.color.DarkColor));
    }
}
 
Example 7
Source File: MusicActivity.java    From LLApp with Apache License 2.0 5 votes vote down vote up
protected void onInitView() {
        setTitle("西西音乐");
        Help.initSystemBar(this, StaticValue.color);//这个对所有的都适合
        Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar1);
        toolbar.setBackgroundColor(StaticValue.color);
        setSupportActionBar(toolbar);
        toolbar.setTitleTextColor(Color.WHITE);//设置ToolBar的titl颜色
        toolbar.setNavigationIcon(R.mipmap.abc_ic_ab_back_mtrl_am_alpha);//必须放在setSupportActionBar后才有用,否则没有,设置返回图标
//        toolbar.setNavigationOnClickListener(back_btn);//添加按键监听
        toolbar.setNavigationOnClickListener(v -> {
            if (mSearchAutoComplete.isShown()) {
                try {
                    mSearchAutoComplete.setText("");
                    Method method = mSearchView.getClass().getDeclaredMethod("onCloseClicked");
                    method.setAccessible(true);
                    method.invoke(mSearchView);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                finish();
            }
        });

        mSectionsPagerAdapter = new MySectionsPagerAdapter(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);
        tabLayout.setTabTextColors(R.color.black,StaticValue.color);
        tabLayout.setSelectedTabIndicatorColor(StaticValue.color);
        tabLayout.setupWithViewPager(mViewPager);

        FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab);
        MDTintUtil.setTint(fab, StaticValue.color);
        fab.setOnClickListener(view -> Snackbar.make(view,"敬请期待", Snackbar.LENGTH_LONG)
                        .setAction("Action",null).show());
    }
 
Example 8
Source File: Wiki.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();

    super.onCreate(savedInstance);

    subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT, "");

    setShareUrl("https://reddit.com/r/" + subreddit + "/wiki/");

    applyColorTheme(subreddit);
    createCustomCss();
    createCustomJavaScript();
    setContentView(R.layout.activity_slidetabs);
    setupSubredditAppBar(R.id.toolbar, "/r/" + subreddit + " wiki", true, subreddit);

    if(getIntent().hasExtra(EXTRA_PAGE)) {
        page = getIntent().getExtras().getString(EXTRA_PAGE);
        LogUtil.v("Page is " + page);
    } else {
        page = "index";
    }
    tabs = (TabLayout) findViewById(R.id.sliding_tabs);
    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabs.setSelectedTabIndicatorColor(new ColorPreferences(Wiki.this).getColor("no sub"));

    pager = (ToggleSwipeViewPager) findViewById(R.id.content_view);
    findViewById(R.id.header).setBackgroundColor(Palette.getColor(subreddit));

    new AsyncGetWiki().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example 9
Source File: CurrencyListTabsActivity.java    From CryptoBuddy with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_currency_list_tabs);
    context = this;
    mToolbar = findViewById(R.id.toolbar_currency_list);
    setSupportActionBar(mToolbar);
    TabLayout tabLayout = findViewById(R.id.currency_list_tabs);
    mViewPager = findViewById(R.id.currency_list_tabs_container);
    libsBuilder = new LibsBuilder()
            //provide a style (optional) (LIGHT, DARK, LIGHT_DARK_TOOLBAR)
            .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
            .withAboutIconShown(true)
            .withLicenseShown(true)
            .withVersionShown(true)
            .withAboutVersionShownName(true)
            .withAboutVersionShownCode(true)
            .withAboutVersionString("Version: " + BuildConfig.VERSION_NAME)
            .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
            .withActivityTitle("CryptoBuddy")
            .withLibraries("easyrest", "materialabout", "androiddevicenames", "customtabs", "togglebuttongroup", "materialfavoritebutton");

    TextDrawable t = new TextDrawable(this);
    t.setText("ART");
    t.setTextAlign(Layout.Alignment.ALIGN_CENTER);
    t.setTextColor(Color.BLACK);
    t.setTextSize(10);
    AccountHeader headerResult = new AccountHeaderBuilder()
            .withActivity(this)
            .withHeaderBackground(t).build();
    drawer = new DrawerBuilder()
            .withActivity(this)
            .withToolbar(mToolbar)
            .withSelectedItem(1)
            .withAccountHeader(headerResult)
            .addDrawerItems(
                new PrimaryDrawerItem().withIdentifier(1).withName(R.string.Home).withIcon(FontAwesome.Icon.faw_home),
                new PrimaryDrawerItem().withIdentifier(2).withName(R.string.News).withIcon(FontAwesome.Icon.faw_newspaper),
                new PrimaryDrawerItem().withIdentifier(3).withName("About").withIcon(FontAwesome.Icon.faw_question_circle),
                new PrimaryDrawerItem().withIdentifier(4).withName("Open Source").withIcon(FontAwesome.Icon.faw_github_square),
                new PrimaryDrawerItem().withIdentifier(5).withName("Rate on Google Play").withIcon(FontAwesome.Icon.faw_thumbs_up)
            )
            .withTranslucentStatusBar(false)
            .build();
    drawer.setOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            switch (position) {
                case 1:
                    drawer.closeDrawer();
                    return true;
                case 2:
                    drawer.closeDrawer();
                    drawer.setSelection(1);
                    startActivity(new Intent(context, NewsListActivity.class));
                    return true;
                case 3:
                    drawer.closeDrawer();
                    drawer.setSelection(1);
                    startActivity(new Intent(context, AboutTheDevActivity.class));
                    return true;
                case 4:
                    drawer.closeDrawer();
                    drawer.setSelection(1);
                    libsBuilder.start(context);
                default:
                    return true;
            }
        }
    });

    mSectionsPagerAdapter = new SectionsPagerAdapterCurrencyList(getSupportFragmentManager());
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.addOnPageChangeListener(this);
    tabLayout.setupWithViewPager(mViewPager);
    tabLayout.setSelectedTabIndicatorColor(Color.WHITE);
}
 
Example 10
Source File: TabLayoutHandler.java    From NightOwl with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(@NonNull View view, @NonNull Object value) {
    TabLayout tabLayout = (TabLayout) view;
    int color = (int) value;
    tabLayout.setSelectedTabIndicatorColor(color);
}
 
Example 11
Source File: ColorUtils.java    From android with Apache License 2.0 4 votes vote down vote up
public static void colorizeTabsAndHeader(Activity activity, Toolbar toolbar, TabLayout tabs,
    int primaryColor, int secondaryColor) {
  tabs.setBackgroundColor(primaryColor);
  tabs.setSelectedTabIndicatorColor(secondaryColor);
  colorizeHeader(activity, toolbar, primaryColor);
}