2014-12-25 3 views
1

새로운 방식으로 탐색함에 코드를 작성하려고합니다. 내 문제는 내 자신의 애플 리케이션 도구 모음을 정의하려고 할 때 온다.Android Studio에서 위젯 툴바를 정의하는 중 오류가 발생했습니다.

여기 내 XML 코드입니다.

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    android:paddingTop="@dimen/app_bar_top_padding" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/primaryColor" 
    app:theme="@style/MyCustomToolBarTheme" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"> 
</android.support.v7.widget.Toolbar> 

는 app_bar.xml 안드로이드 스튜디오의 미리보기에서

이며, 나는 다음과 같은 오류지고있어 그것을 렌더링 할 때 :

* 누락 스타일. 이 레이아웃에 올바른 테마가 선택 되었습니까? 레이아웃 위에있는 테마 콤보 상자를 사용하여 다른 레이아웃을 선택하거나 테마 스타일 참조를 수정하십시오.
- 현재 테마에서 스타일 'toolbarStyle'을 찾지 못했습니다. (유사한 오류 4 개가 표시되지 않음)

- 속성 "minHeight"의 "? attr/actionBarSize"는 유효한 형식이 아닙니다. (편집) (2 개의 유사한 오류가 표시되지 않음) *

어떻게 해결할 수 있습니까 ??

정말 고마워요.

답변

1

비슷한 오류가있어서 style.xml 파일의 parent 특성을 변경하여 해결했습니다. 내 도구 모음 위젯

<resources> 
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
</style> 

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
</style> 

<style name="Widget.MyApp.ActionBar" parent="AppTheme"> 
    <item name="android:background">@color/title_color</item> 
</style> 

</resources> 

그리고 :

의 AndroidManifest.xml :

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 

styles.xml이 솔루션은 응용 프로그램 테마로 동일한 상위 테마를 사용 아래와 같이하는 것입니다

<android.support.v7.widget.Toolbar 
    android:id="@+id/title_bar" 
    android:gravity="top|center" 
    style="@style/Widget.MyApp.ActionBar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"/> 

색상 맞춤 설정을 toolb 대신 styles.xml에 넣는 것이 좋습니다. ar 위젯.

0

아주 오래된 질문입니다. 당신은

<style name="AppBaseTheme" parent="Theme.AppCompat"> </style> 

등의 작업 표시 줄 테마를 사용해야하며 ATTR에 대한 올바른 sintax은 다음과 같습니다

?android:attr/actionBarSize 
0

잠시 동안 stuggling 후,이 코드가 작동 나를 위해 :

<resources> 

    <!-- Base application theme. --> 
    <style name="MyCustomToolbarTheme" parent="android:Theme.Material.Light> 
     <item name="toolbarStyle">@style/ToolbarStyle</item> 
    </style> 

    <style name="ToolbarStyle" parent="Theme.AppCompat"> 
     <item name="android:textColorPrimary">@android:color/white</item> 
     <item name="android:textColorSecondary">@android:color/white</item> 
     <item name="android:actionMenuTextColor">@android:color/white</item> 
    </style> 

</resources> 

toolbarStyle 필드가 누락되어 기입해야 할 수 있습니다.

관련 문제