2012-07-25 3 views
2

Holo와 유사한 ActionBar 탭 배경을 만들 수 있습니까 에만 xml 드로어 블이 있습니까? 그렇다면 어떻게? 그렇지 않은 경우 제한 사항은 무엇입니까?xml이 포함 된 ActionBar 탭 배경

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- Non focused states --> 
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_holo" /> 
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_holo" /> 

    <!-- Focused states --> 
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_holo" /> 
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_holo" /> 

    <!-- Pressed --> 
    <!-- Non focused states --> 
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_holo" /> 
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_holo" /> 

    <!-- Focused states --> 
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_holo" /> 
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_holo" /> 
</selector> 

그리고 같은 tab_selected_holo.9.png 각 상태에 대해 9 패치 드로어 블을 사용하여 :

enter image description here

내가 탭 배경이 tab_indicator_holo.xml의 선택 당김으로 정의되어있는 안드로이드 소스 코드를 찾아.

9 개의 패치 드로어 블이 레이어 목록 드로어 블, 드로어 블 Drawble 또는 조합으로 대체 될 수 있는지 궁금 해서요. 따라서 다양한 PNG 파일을 만들 필요가 없습니다.

ActionBarSherlock도 9 개의 패치 드로어 블을 사용하므로이 방법이 유일한 방법 일 가능성이 높습니다.

+0

내가 뭘하면 안드로이드 플랫폼 자원 폴더를 복사하여 조정할 수있는 약간 –

+0

@ 그건 내가 너무하는 일이다 ferdy182, 나는 그것을 피하기를 원할 것이다. 18 개의 파일로 탭의 모양과 색상을 하드 코딩하는 것을 좋아하지 않습니다. – hpique

+1

어쩌면 이것이 질문에 대답하지 않더라도 약간 도움이 될 것입니다. –

답변

2

ActionBar 탭을 완전히 사용자 정의하려면 "Home"이라는 가상의 탭에 대해 다음과 같이 시도하십시오. 이 레이아웃에는 이미지와 레이블이 들어 있습니다.

(1) 정상적으로 탭을 만들 수 있지만 ActionBar.Tab.setCustomView()를 통해 사용자 지정 레이아웃을 지정

// Home tab 
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
HomeFragment homeFragment = new HomeFragment(); 
RelativeLayout layoutView = (RelativeLayout)inflater.inflate(R.layout.layout_tab_home, null); 
TextView title = (TextView)layoutView.findViewById(R.id.title); 
ImageView img = (ImageView)layoutView.findViewById(R.id.icon); 
ActionBar.Tab tabHome = mActionBar.newTab(); 
tabHome.setTabListener(homeFragment); 
title.setText(this.getString(R.string.tabTitleHome)); 
img.setImageResource(R.drawable.tab_home); 
tabHome.setCustomView(layoutView); 
mActionBar.addTab(tabHome); 

(2) 탭 레이아웃을 생성 (layout_tab_home.xml)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="56dip" android:layout_weight="0" android:layout_marginLeft="0dip" android:layout_marginRight="0dip"> 
    <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:paddingBottom="2dip" /> 
    <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/icon" android:paddingLeft="0dip" android:paddingRight="0dip" style="@style/tabText" /> 
</RelativeLayout> 

(3)이 예에서 이미지

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_selected="true" android:drawable="@drawable/home_sel" /> 
    <item android:state_selected="false" android:drawable="@drawable/home_unsel" /> 
</selector> 

에 대한 드로어 블을 설정, 난 그냥 diff't COL와 PNG 그래픽이 ors 선택한 상태 대 선택되지 않은 상태

BACKGROUND 드로어 블에 가장 관심이있는 것처럼 보입니다. 따라서 같은 일이 적용되지만 RelativeLayout에 배경 드로어 블을 설정하고 위와 유사한 선택기를 사용하십시오.

+0

나는 PNG를 전혀 사용하지 않고 대신 구성된 드로어 블만을 사용하는 것에 관한 질문이라고 생각합니다. –

+0

예. 어쨌든 CSmith를 시도하기위한 것보다 내가 묻고있는 것이 아니라. – hpique

0

인셋 드로어 블을 사용하여 아래쪽에 줄무늬를 만들 수 있습니다. 이 xml은 게시 한 것과 같이 하단에 파란색 선이있는 흰색 직사각형을 만듭니다. 그런 다음 해당 상태에 대해 상태 목록 드로어 블을 사용할 수 있습니다. 당신이 게시물에 모습을 가질 수 있습니다 더 많은 정보

<?xml version="1.0" encoding="utf-8"?> 
<inset xmlns:android="http://schemas.android.com/apk/res/android" 
android:insetBottom="0dp" 
android:insetLeft="-5dp" 
android:insetRight="-5dp" 
android:insetTop="-5dp" > 

<shape> 
    <solid android:color="#FFF" /> 

    <stroke 
     android:width="3dp" 
     android:color="#00F" /> 
</shape> 
</inset> 

가 : http://blog.stylingandroid.com/archives/1329

관련 문제