2013-07-17 3 views
5

스타일을 어떻게 수정하든 관계없이 빨간색 화살표가 가리키는 상자의 배경색은 배경에서 변경되지 않습니다.ActionBar 제목의 배경색을 변경하는 방법은 무엇입니까?

img

어떻게 그 색상을 변경합니까? 나는 4.0+를 목표로하고 4.0- 장치와 OS를 신경 쓰지 않습니다.

my styles.xml file에 대한 링크가 있습니다. 죄송합니다.이 프로젝트가 NDA에 속하기 때문에 몇 가지 검열을해야했습니다. 포함

내가 시도 많은 일 :

  • 는 변경 actionBarWidgetStyle
  • android:background 변경 actionBarStyle
  • android:background 변경 windowTitleBackgroundStyle
  • android:background 변경 android:actionBarItemBackground

그 중 누구도 일하지 않았습니다. 해당 텍스트보기는 항상 내 기본 테마의 android:background 값에 충실한 것으로 보이며 아무 것도이를 무시할 수 없었습니다.

무엇이 잘못되었거나 잘못 되었습니까?

+0

http://jgilfelt.github.io/android-actionbarstylegenerator를 사용하여 리소스 세트를 생성하고 아직 시도하지 않은 관련성이있는 내용을 확인하십시오. – CommonsWare

답변

1

XML 파일의 interisting 부분이있다 :

<!-- ActionBar --> 
    <style name="CCCWidgetActionBar" parent="@android:style/Widget.Holo.ActionBar"> 
     <item name="android:background">@color/nav_background</item> 
     <item name="android:textColor">@color/nav_text</item> 
     <item name="android:titleTextStyle">@style/CCCWidgetActionBarTitle</item> 
     <item name="android:textViewStyle">@style/CCCWidgetActionBarTitle</item> 

     <item name="android:windowTitleStyle">@style/CCCWindowTitle</item> 
     <item name="android:windowTitleBackgroundStyle">@style/CCCWindowTitleBackground</item> 
     <item name="android:windowBackground">@color/nav_background</item> 
    </style> 

그냥 변경 :

<item name="android:background">@color/nav_background</item> 

<item name="android:background">@color/pink</item> 

또는 다른 어떤 색깔.

나를 위해 잘 작동합니다.

+0

내 Galaxy S II에서 작동하지 않습니다. 질문에 언급 된 것과 같은 문제. – chakrit

+0

제목 텍스트는 작업 표시 줄 배경을 사용하지 않고 응용 프로그램 배경 스타일 만 사용합니다. 이렇게하면 다른 모든 배경색을 변경하지 않고 해당 특정 색상을 변경할 수 없습니다. – chakrit

+0

내 Lenovo S880에도 동일한 문제가 있습니다. 아마 이것이 기기 문제 일지 모르지만 Google+ 앱은 동일한 기기에서 멋진 액션 바 색상을가집니다. 이상한 – Zyoo

1

사용자 정의 액션 바를 만들고 원하는대로 제목 배경색을 변경할 수 있습니다.

이 단계에 따라 이에 대한

만 할 수는 제목의 사용자 지정 셜록 줄을 만들 수 있습니다.

응용 프로그램의 title에 대한 별도의 XML 파일을 만듭니다. 파일은 다음과 같이 포함

..이 사용자 정의 레이아웃에서

, 우리가 할 수있는 MainActivity를 들어 .. 색상 코드를 사용하여

header_sherlock.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 
android:weightSum="3" 
android:background="#008000" 
> 

    <TextView 
    android:id="@+id/header_tvleft" 
    android:layout_width="0dp" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:gravity="left" 
    android:layout_marginTop="@dimen/margintop" 
    android:clickable="true" 
    android:paddingLeft="@dimen/layoutpaddingleft" 
    android:text="Textview" 
    android:textColor="#ffffff" 
    android:textSize="@dimen/header_leftbtn" 
    /> 


<TextView 
    android:id="@+id/header_tvcenter" 
    android:layout_width="0dp" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:gravity="center_horizontal" 
    android:layout_marginTop="@dimen/margintop" 
    android:layout_marginRight="@dimen/sherlockpaddingright" 
    android:layout_marginLeft="@dimen/sherlockpaddingleft" 
    android:text="Textview" 
    android:textColor="#ffffff" 
    android:textStyle="bold" 
    android:textSize="@dimen/header_title" 
    /> 

    <TextView 
    android:id="@+id/header_tvright" 
    android:layout_width="0dp" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:gravity="right" 
    android:layout_marginTop="@dimen/margintop" 
    android:clickable="true" 
    android:paddingRight="@dimen/layoutpaddingright" 
    android:text="Textview" 
    android:textColor="#ffffff" 
    android:textSize="@dimen/header_rightbtn" 
    /> 

</LinearLayout> 

를 배경 색상을 변경할 수 또는 어떤 활동을 추가하고 싶은지 제목 :

  getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    getSupportActionBar().setCustomView(R.layout.header_sherlock); 
    header_tvleft = (TextView) findViewById(R.id.header_tvleft); 
    header_tvleft.setText("LeftTitleName"); 
    header_tvcenter = (TextView) findViewById(R.id.header_tvcenter); 
    header_tvcenter.setText("CenterTitleName"); 
    header_tvright = (TextView) findViewById(R.id.header_tvright); 
    header_tvright.setText("RightTitleName"); 

시도해보십시오. s 방법 ..

+0

ActionBarSherlock을 사용하지 않고 Android ActionBar 만 사용하면 가능합니까? – chakrit

0

이것은 오래된 질문이지만, 난 그냥 정확히 같은 문제를 했어 - 나에게 문제가 I이 있다고했다 : btn_dark가 정의 일반 버튼의 재 사용 당김이었다

<item name="android:actionBarItemBackground">@drawable/btn_dark</item> 
<item name="actionBarItemBackground">@drawable/btn_dark</item> 

enabled, pressed 및 disabled 상태에 대한 색상입니다. 그것은 새로운 장치에 잘 작동하지만 내 오래된 2.3 전화에서 나는 제목에 회색 배경을 얻고 있었다.

흥미롭게도 비활성 상태 (어두운 회색으로 설정)는 이전 장치에서 작업 표시 줄 제목의 배경에 적용되었습니다. 비활성화 된 색상을 투명하게 설정하면 문제가 해결됩니다. 이 도움이 될 것입니다 희망

<style name="CCCBaseTheme" parent="@android:style/Theme.Holo"> 
    <item name="android:windowBackground">@color/nav_background</item> 
    <item name="android:textColor">@color/text</item> 

    <item name="android:actionBarStyle">@style/CCCWidgetActionBar</item> 

</style> 

windowBackground

와 배경 :

4

그럼 당신은 안드로이드를 변경해야합니다.

+0

와우, 2 년 후에 하하. 더 이상 질문의 맥락에서 테스트 할 수 없기 때문에 이것이 올바른 해결책인지 확신 할 수 없습니다. 누군가 다른 사람이 와서이 작품이 작동한다고 말하면 받아 들일 것입니다. – chakrit

+0

hehe 어제 나는 항상 사용자 정의 작업 표시 줄을 사용 하여이 문제에 직면 : S .... 나는 (windowBackground) 그것을 테스트하고 잘하고있다 :) –

관련 문제