2017-08-16 43 views
0

我有一个从android.support.v4.app.Fragment扩展的片段类。现在,在它的布局我还补充说:Theme.AppCompat片段类

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal"> 


<android.support.design.widget.AppBarLayout 
    android:id="@+id/appBarLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar_chat_activity" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:layout_gravity="center_horizontal" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay"> 


     <ImageView 
      android:id="@+id/imageView" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:src="@drawable/loaded_items" 
      tools:layout_editor_absoluteX="16dp" 
      tools:layout_editor_absoluteY="-15dp"/> 

     <TextView 
      android:id="@+id/txv_count_notify" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:textColor="#0000" 
      android:textSize="12sp" 
      android:textStyle="bold" 
      tools:text="32546874"/> 

    </android.support.v7.widget.Toolbar> 

</android.support.design.widget.AppBarLayout> 

,但我得到这个错误,并没有什么显示布局:

Select Theme.AppCompat or a descendant in the theme selector 

这是我的styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

我使用片段,我不想使用活动并从延伸AppCompatActivity。你的建议是什么?

回答

0

可能问题出在您的@style/AppTheme.PopupOverlay@style/AppTheme.AppBarOverlay。可能不会继承AppCompat主题。 parent="..."标签可能会覆盖使用的文件内继承AppTheme.<child_theme_name>

您是否搜索过相同的问题?

+0

你是什么意思?这是在清单文件中:'android:theme =“@ style/AppTheme”> –

+0

请给@ style/AppTheme.PopupOverlay和@ style/AppTheme.AppBarOverlay –

+0

styles.xml这是我的整个styles.xml包含:' <! - Base application theme。 - > ' –

0

试试以下主题:

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">