2012-09-25 2 views
0

특정보기에 맞춤 구성표 (스타일)를 적용하는 데 문제가 있습니다. 나는 MainActivity의button-textColor에 Android 사용자 정의 스타일/체계가 올바르게 적용되지 않았습니다.

<application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 


     <activity 
      android:name=".MainActivity" 
      android:label="@string/title_activity_main" 
      android:theme="@style/myStyle1" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
      . 
      . 
      . 
    </application> 

레이아웃처럼, 내 간단한 테스트 응용 프로그램의 주요 활동에이 스타일을 적용했습니다

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 


    <style name="myStyle1"> 
     <item name="android:layout_width">fill_parent</item> 
     <item name="android:layout_height">wrap_content</item> 
     <item name="android:textColor">@color/red</item> 
     <item name="android:textColorHighlight">@color/blue</item> 
     <item name="android:textColorHint"> @color/fuchsia</item> 
     <item name="android:textColorLink">@color/olive</item> 
     <item name="android:typeface">serif</item> 
    </style> 

    <style name="AppTheme" parent="android:Theme.Light" /> 

</resources> 

고해상도/값/styles.xml에 내 자신의 스타일을 정의 버튼 몇 개, textViews 몇 개가 포함되어 있습니다. 그 중 일부는 명시 적으로 스타일 속성이 지정되어 있으며, 다른 일부는 전체 활동에서 상속해야합니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/layout_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/silver" 
    android:orientation="vertical" > 

    <EditText android:id="@+id/edit_message" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:hint="@string/edit_message" /> 

    <Button android:id="@+id/send_button" 
     style="@style/myStyle1" 
     android:text="@string/button_send" /> 

    <Button android:id="@+id/relative_activity" 
     android:text="@string/rel_activitity_text" 
     android:onClick="startRelativeActivity"/> 

    <Button android:id="@+id/button_TTT" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:textColor="@color/red" 
     android:text="@string/button_TTT" /> 

    <fragment android:name="my.firstapp.Fragment1" 
      android:background="@color/red" 
      android:id="@+id/list" 
      android:layout_weight="1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

</LinearLayout> 

는 지금까지 내가, 활동의 모든 것이 내가 정의 ahve 스타일에 따라 양식에 일치해야한다 말할 수있는, 그러나 이것은 당신이 볼 수 있듯이 나는

weird scheme

을 얻을 것입니다 지정된 스타일의 버튼에만 빨간색으로 텍스트가 표시되고 다른 버튼에는 텍스트가 표시되지 않습니다. 그러나 흰색 단추조차 체계에서 정확한 글꼴을 얻는다, 그래서 적어도 그것의 약간은 적용되고있다. 왜 그게 전부가 아니겠습니까? 도움이된다면, 나는 완전히 혼란스러워합니다.

답변

0

모든 버튼에 대해 글로벌 스타일을 원한다면 이와 같은 작업을 수행해야합니다. 당신의 안드로이드 당신이 테마를 설정해야 매니페스트에

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 

<style name="myStyle1"> 
    <item name="android:layout_width">fill_parent</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:textColor">@color/red</item> 
    <item name="android:textColorHighlight">@color/blue</item> 
    <item name="android:textColorHint"> @color/fuchsia</item> 
    <item name="android:textColorLink">@color/olive</item> 
    <item name="android:typeface">serif</item> 
</style> 

<style name="AppTheme" parent="android:Theme.Light"> 
    <item name="android:buttonStyle">@style/myStyle1</item> 
</style> 

</resources> 

...

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 

    <activity 
     android:name=".MainActivity" 
     android:label="@string/title_activity_main" 
     android:theme="@style/AppTheme" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
     . 
     . 
     . 
</application> 

당신은 등 checkboxs이 링크에서 더 많은 정보를 위해 같은 일을 할 수 있습니다. http://developer.android.com/reference/android/R.attr.html

또한 다음 레이아웃에서이를 테스트했습니다. 3 개의 버튼에는 모두 빨간색 글자가 있어야합니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/layout_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffaaaaaa" 
    android:orientation="vertical" > 

<EditText android:id="@+id/edit_message" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0" 
    android:hint="edit_message" /> 

<Button android:id="@+id/send_button" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="button_send" /> 

<Button android:id="@+id/relative_activity" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="rel_activitity_text" 
    android:onClick="startRelativeActivity"/> 

<Button android:id="@+id/button_TTT" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0" 
    android:textColor="#ffff0000" 
    android:text="button_TTT" /> 

<!--<fragment android:name="my.firstapp.Fragment1" 
     android:background="#00ff0000" 
     android:id="@+id/list" 
     android:layout_weight="1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" />--> 

</LinearLayout> 
+1

어떤 방식 으로든 버튼이 변경되지는 않습니다. 심지어 더 이상한 것은 아무것도 바뀌지 않는다는 것입니다. 이 AppTheme은 버튼의 스타일 만 정의하고 나머지는 기본값으로 설정해야한다고 생각 하긴하지만 textEdits는 여전히 보라색을 유지합니다. –

+0

MainActivity에서 단추를 그래픽으로 변경하고 있습니까? 그것은 테마를 무시할 것입니다. – frognosis

+0

아니, setContentView (R.layout.activity_main); onCreate()에서 액티비티에서 진행되는 유일한 작업입니다. –