9

안녕하세요 저는 주 활동을 위해 맞춤형 Backgroundlayout을 적용하고 싶습니다. 해결책을 찾지 못했습니다. 누군가 나에게 몇 가지 조언을 해줄 수 있습니까?ActionBarSherlock에서 제목 중력을 가운데로 설정하십시오.

은 작업 표시 줄에 배경이있는 간단한 TextView를 갖고 싶어합니다. 이것이 가능한가?

아이콘을 제거하고 배경 이미지를 설정할 수있었습니다. 그러나 텍스트의 중력을 중심으로 설정하고 typefont를 어떻게 바꿀 수 있습니까?

getSupportActionBar().setDisplayShowHomeEnabled(false); 
    getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(myimage)); 

그것은 다음과 같아야합니다 enter image description here

감사합니다!

답변

16

는이 같은 실행 바에 대한 사용자 지정 레이아웃을 설정해야합니다 : 레이아웃에서

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
getSupportActionBar().setCustomView(R.layout.yourlayout); 

당신이 다음 텍스트 뷰를 추가하고 center에 그 무게를 설정할 수 있습니다. 예컨대 :

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="Header!" 
     android:id="@+id/mytext" 
     android:textColor="#ffffff" 
     android:textSize="25dp" /> 

</LinearLayout> 

그런 다음이 같은 자산에서 활동 내에서 사용자 정의 typefont을 설정할 수 있습니다 당신이 어떤 탭이있는 경우,이 끔찍하게 잘못

TextView txt = (TextView) findViewById(R.id.mytext); 
Typeface font = Typeface.createFromAsset(getAssets(), "yourfont.ttf"); 
txt.setTypeface(font); 
+3

. 탭은 남아 있지만 제목은 BENEATH로 바뀝니다. htem – Adam

+1

Ahmad Rocks ;-) –

관련 문제