2014-10-23 2 views
2

Android 플랫폼 용 탭에 이미지를 표시하기위한 customrenderer를 만들었습니다. 이제 어떤 탭이 선택되었는지 보여주는 밑줄을 어떻게 제거 할 수 있는지 알고 싶습니다. 또한 사용자 정의 렌더러를 만드는 방법에 대한 정보를 얻을 수 있습니까? YouTube에서 보였지만, 둥근 모서리를 가진 예는Xamarin forms : android에 대한 CustomTabRenderer로 선택된 탭의 파란색 선 숨기기

namespace Plopsa.Android 
{ 
public class CustomTabRenderer: TabbedRenderer 
{ 
    private Activity _activity; 

    protected override void OnModelChanged(VisualElement oldModel, VisualElement newModel) 
    { 
     base.OnModelChanged(oldModel, newModel); 

     _activity = this.Context as Activity; 
    } 

    // May put this code in a different method - was just for testing 
    public override void OnWindowFocusChanged(bool hasWindowFocus) 
    { 
     // Here the magic happens: get your ActionBar and select the tab you want to add an image 
     ActionBar actionBar = _activity.ActionBar; 

     if (actionBar.TabCount > 0) 
     { 
      ActionBar.Tab tabOne = actionBar.GetTabAt(0); 
      tabOne.SetIcon(Resource.Drawable.icon_tab1); 

      ActionBar.Tab tabTwo = actionBar.GetTabAt(1); 
      tabTwo.SetIcon (Resource.Drawable.icon_tab2); 

      ActionBar.Tab tabThree = actionBar.GetTabAt(2); 
      tabThree.SetIcon(Resource.Drawable.icon_tab3); 

      ActionBar.Tab tabFour = actionBar.GetTabAt(3); 
      tabFour.SetIcon(Resource.Drawable.icon_tab4); 

     } 
     base.OnWindowFocusChanged(hasWindowFocus); 
    } 
} 
+0

동일한 결과 probl 너 ... 그럴 수있어? –

+0

Xamarin에서 API 레벨 23을 사용하면 ActionBar.Tab가 더 이상 사용되지 않습니다. – 476rick

답변

0

당신은 Tabbar.axml 클래스 설정하여 원하는 결과를 얻을 수 있습니다 ... 많이 표시되지 않습니다 다음과 같은 값으로 '안드로이드 tabIndicatorColor를' 'android : background'.

다음은 탭 배경색과 일치하는 탭 표시기로 원하는 결과를 보여주는 코드입니다. 이것은 모두 Tabbar.axml 파일에 포함되어 있습니다. MainActivitiy.cs에서 탭을 등록 할 수 있습니다.

Tabbar.axml

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" app:tabTextAppearance="@style/MyCustomTabText" android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:theme="@style/ThemeOverlay.AppCompat.Light" app:tabTextColor="@color/primaryOrange" app:tabIndicatorColor="?attr/colorPrimary" app:tabIndicatorHeight="0dp" app:tabSelectedTextColor="@color/primaryOrange" app:tabGravity="fill" app:tabMode="fixed" /> MainActivity.cs

protected override void OnCreate(Bundle bundle) 
     { 

      TabLayoutResource = Resource.Layout.Tabbar; 
      ToolbarResource = Resource.Layout. 

      base.OnCreate(bundle); 

      Xamarin.Forms.Forms.Init(this, bundle); 

      LoadApplication(new App()); 

     } 

enter image description here