2016-07-29 3 views
0

전체 응용 프로그램의 기본 스타일과 텍스트보기의 하위 스타일을 가지고 있습니다. 그러나 자식 스타일에서는 "accentColor"항목이 효과적이지 않습니다. 텍스트 뷰는 여전히 부모 스타일에서 accentColor를 사용합니다. 여기 colorAccent를 자식 테마로 재정의 할 수 없습니다.

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">#00ff00</item> <!-- Green color --> 
</style> 

<style name="MyCustomTheme" parent="AppTheme"> 
    <item name="colorAccent">#ff0000</item> <!-- Red color --> 
</style> 

</resources> 

내 레이아웃 파일입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="io.github.seemuch.highlightexperiment.MainActivity"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello World!" 
    android:textIsSelectable="true" 
    android:textColorHighlight="" 
    style="@style/TextViewTheme"/> 

</RelativeLayout> 

그리고 여기에 응용 프로그램의 스크린 샷입니다 : screenshot

당신이 볼 수 있듯이 여기

내 style.xml입니다 텍스트보기의 강조 색상은 녹색이며 TextViewTheme이 아닌 AppTheme의 accentColor입니다.

텍스트 하이라이트의 색상을 변경하고 싶습니다. 텍스트보기에 "textColorHighlight"속성을 추가하여 강조 부분 자체를 변경할 수는 있지만 "앵커"의 색상은 변경되지 않습니다. 내가 찾은 유일한 방법은 강조 색상을 변경하는 것이었지만 전체 앱의 강조 색상을 변경하고 싶지 않았습니다.

누구나 아이 스타일에서 액센트 컬러를 만드는 법을 아는 사람이 있습니까? 또는 앵커의 색상을 변경하는 더 좋은 방법이 있습니까?

+0

''태그 안에있는'manifest.xml'의 특정 활동에 테마를 추가 할 수 있습니다.이 태그는'AppTheme'을 오버라이드 할 것입니다. –

+0

"android : style"대신 "android : style" "스타일"? –

답변

0

colorAccent은 테마 속성이며 Themes and Styles I/O 2016 talk에 따른 스타일 속성이 아닙니다.

따라서 당신은하지 style로, android:theme으로 적용해야합니다

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello World!" 
    android:textIsSelectable="true" 
    android:textColorHighlight="" 
    android:theme="@style/MyCustomTheme"/> 

그리고 당신의 MyCustomTheme이 아닌 (단지 그것을 정의하는 일을 변경) 기본 테마를 오버레이로 ThemeOverlay.AppCompat의 부모가 일반적으로해야한다 부모 테마에서 모든 것을 재설정합니다.

+0

이것이 제대로 작동할까요? 내가 이해하는 방식으로, 테마는 응용 프로그램, 활동 및 ContextWrappers에만 적용될 수 있습니다. – lionscribe

+0

Lollipop 및 AppCompat v21 이후로는 그렇지 않습니다. – ianhanniballake

+0

어쩌면 당신 말이 맞지만 문서는 다르지 않습니다. – lionscribe

관련 문제