Задать вопрос
SAlenaA
@SAlenaA

Как увеличить иконки в TabLayout?

Подскажите, пожалуйста, как увеличить иконки:
мое активити:
<android.support.v4.widget.DrawerLayout 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/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".RoutesActivity">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/rootLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipeRefreshLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <android.support.v4.view.ViewPager
                android:id="@+id/viewPager"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#ffffce" />
        </android.support.v4.widget.SwipeRefreshLayout>

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

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                app:contentScrim="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
                <!--app:expandedTitleMarginBottom="80dp"-->

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    android:src="@drawable/aigir_01_720"
                    app:layout_collapseMode="parallax"
                    app:layout_collapseParallaxMultiplier="0.5" />

                <include layout="@layout/toolbar_routes" />
            </android.support.design.widget.CollapsingToolbarLayout>
            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_gravity="bottom"
                app:tabGravity="fill"
                app:tabMode="fixed" />
            <k7i3.code.tnc.transport.widget.SlidingTabLayout
                android:id="@+id/slidingTabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|enterAlways"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
        </android.support.design.widget.AppBarLayout>

        <!--TODO http://blog.grafixartist.com/toolbar-animation-with-android-design-support-library/  http://android-developers.blogspot.ru/2015/05/android-design-support-library.html-->
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/favoritesFAB"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:src="@drawable/ic_favorite_white_24dp"
            app:layout_anchor="@+id/viewPager"
            app:layout_anchorGravity="bottom|end"
            android:layout_marginBottom="@dimen/fab_margin_bottom_anchor_favorites"
            android:layout_marginEnd="@dimen/fab_margin_end_anchor"
            app:backgroundTint="#f15257"/>
        <!--app:layout_behavior="k7i3.code.tnc.transport.widget.behavior.ScrollAwareFABBehavior"-->
        <!--app:fabSize="mini"-->

        <!--TODO waiting for built-in implementation of ScrollAwareFABBehavior https://guides.codepath.com/android/Floating-Action-Buttons-->
        <!--FAB for content = recycleView (with hidden anim)-->
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/mapsFAB"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:src="@drawable/ic_navigation_white_24dp"
            app:layout_anchor="@+id/viewPager"
            app:layout_anchorGravity="bottom|end"
            android:layout_marginBottom="@dimen/fab_margin_bottom_anchor"
            android:layout_marginEnd="@dimen/fab_margin_end_anchor"/>
        <!--app:layout_behavior="k7i3.code.tnc.transport.widget.behavior.ScrollAwareFABBehavior"-->

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

    <include layout="@layout/nav_drawer" />
</android.support.v4.widget.DrawerLayout>


RoutesActivity класс:
public class RoutesActivity extends BaseActivity {

  //  private CharSequence titles[] = {"Автобусы","Троллейбусы", "Школьники", "Электрички" , "Избранные"};
    private CharSequence titles[] = {"","", "", "" , ""};
    private Integer[] iconResourceArray = { R.mipmap.ic_launcher_bus, R.mipmap.ic_launcher_trolleybus, R.mipmap.ic_launcher_school,
    R.mipmap.ic_launcher_train, R.mipmap.ic_launcher_favorite};
....

 viewPager = (ViewPager) findViewById(R.id.viewPager);
        routesPagerAdapter = new RoutesPagerAdapter(getSupportFragmentManager(),titles);

        viewPager.setAdapter(routesPagerAdapter);

        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewPager);
        for (int i = 0; i < iconResourceArray.length; i++) {
            tabLayout.getTabAt(i).setIcon(iconResourceArray[i]);
        }
.......


public class RoutesPagerAdapter extends FragmentPagerAdapter {
    private static final String TAG = "====> RoutesPagerAdapter";
    CharSequence titles[];

    public RoutesPagerAdapter(FragmentManager fm, CharSequence titles[]) {
        super(fm);
        this.titles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        Log.d(TAG, "getItem()");
        switch (position) {
            case 0: return RoutesFragment.newInstance(position);
            case 1: return FavoritesRoutesFragment.newInstance(position);
            default: return RoutesFragment.newInstance(position);
        }
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

    @Override
    public int getCount() {
        return titles.length;
    }
  • Вопрос задан
  • 97 просмотров
Подписаться 1 Простой 1 комментарий
Решения вопроса 1
SAlenaA
@SAlenaA Автор вопроса
Вот решение нашла:
for (int i = 0; i < iconResourceArray.length; i++) {

            ImageView imgView= new ImageView(RoutesActivity.this);
            imgView.setImageResource(iconResourceArray[i]);
            imgView.setPadding(0,0,0,0);
            tabLayout.getTabAt(i).setCustomView(imgView);

        }
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы