0

내가 뭘하고 있는가하는 것은 내가 Toolbar, StatusBar하고 실용적으로 기본 theme 색상, 내가 성공적으로 모든 widgets의 색상을 변경할 수 있어요하지만 몇 가지 유형을 얻는 이외의 Tablayout 색상을 변경하는 것을 시도하고있다 Tablayout에서 앱 테마의 기본 색상의 경계를 알 수없는 이유는 무엇입니까? 아무도 그것을 제거하는 방법을 말해 줄 수 있습니까? 기본 스타일은 Tablayout의 모서리가 직사각형이 아니므로 정의됩니다.안드로이드 프로그래밍 TabLayout 배경을 변경하는 방법

화면 :

here green color visible at boundaries of Tablayout is the apps theme color

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/app_bar_container" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context=".mainFlow.MainActivity"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar_main" 
    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/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabGravity="fill" 
     android:background="@color/colorPrimaryDark" 
     app:tabIndicatorHeight="2dp" 
     app:tabMode="fixed" 
     app:tabIndicatorColor="@color/white"/> 

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


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

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

사용'응용 프로그램 : tabBackground는 = "@ 드로어 블/colorPrimaryDark " ' – Wizard

+0

@Wizard 배경색을 프로그래밍 방식으로 변경하고 싶습니다 –

답변

-1

당신은 TabLayout의 테마를 설정할 수 있습니다.

<style name="MyTabLayout" parent="android:Widget"> 
     <item name="tabBackground">@drawable/tab_background</item> 
</style> 

이 테마를 사용자의 TabLayout으로 설정하십시오.

0

이 시도 :

귀하의 XML :

<android.support.design.widget.TabLayout 
    .... 
    app:tabBackground="@drawable/tab_color_selector" 
    ... 
    /> 

과 선택 고해상도/드로어 블/사진 tab_color_selector.xml :

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@color/tab_background_selected" android:state_selected="true"/> 
    <item android:drawable="@color/tab_background_unselected"/> 
</selector> 
+0

프로그래밍 방식으로 배경색을 변경하고 싶습니다 어떻게 가능합니까? 블 리 –

+0

이것을 시도하십시오 :'tabLayout.setBackground (ContextCompat.getDrawable (context, R.drawable.tab_color_selector));'@ kapil-rajput – shmakova

관련 문제