2016-08-05 17 views
4

嗨,我已經創建了一個簡單的應用程序,並測試了它在Android 4.4.4和4.4.4奇巧上述應用欄標題中的Android 5.0不顯示以上

- 它工作正常(我可以看到稱號應用欄)

enter image description here

但是,當我測試它的Android 5.0以上,標題是不可見的

enter image description here

Styles.xml

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="AppTheme.Base"> 
     <!-- Customize your theme here. --> 
    </style> 

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="colorPrimary">@color/colorPrimaryDark</item> 
     <item name="colorPrimaryDark">@color/colorPrimary</item> 
     <item name="colorAccent">@color/colorAccent</item> 

    </style> 


    <style name="myCustomAppBarTheme" parent="ThemeOverlay.AppCompat.Light"> 
     <item name="android:textColorPrimary">@color/colorPrimaryDark</item> 
     <item name="android:textColorSecondary">@color/colorPrimary</item> 
    </style> 

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

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 


    <!--************************* Custom Theme ******************************* --> 
    <style name="myCustomAppBarTheme_old" parent="Theme.AppCompat.Light"> 
     <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item> 
     <item name="actionBarStyle">@style/AppTheme.ActionBar</item> 
    </style> 

    <style name="AppTheme.ActionBar" parent="Widget.AppCompat.Light.ActionBar"> 
     <item name="android:titleTextStyle">@style/AppTheme.ActionBar.TitleText</item> 
     <item name="titleTextStyle">@style/AppTheme.ActionBar.TitleText</item> 
     <item name="android:height">100dp</item> 
     <item name="height">100dp</item> 
     <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item> 
    </style> 

    <style name="AppTheme.ActionBar.TitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title"> 
     <item name="android:textSize">20sp</item> 
     <item name="android:textColor">@color/colorWhite</item> 
    </style> 


    <!--**************************** Custom Theme ******************************* --> 



    <!--**************************** Switch Theme ******************************* --> 
    <style name="SCBSwitch" parent="Theme.AppCompat.Light"> 
     <!-- active thumb & track color (30% transparency) --> 
     <item name="colorControlActivated">@color/colorPrimaryDark</item> 

     <!-- inactive thumb color --> 
     <item name="colorSwitchThumbNormal">#f1f1f1 
     </item> 

     <!-- inactive track color (30% transparency) --> 
     <item name="android:colorForeground">#42221f1f 
     </item> 
    </style> 
    <!--**************************** Switch Theme ******************************* --> 

</resources> 

Dashboard.xml活動

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

    <!-- Include Appbar --> 
    <include 
     android:id="@+id/app_bar_dashboard" 
     layout="@layout/app_bar_dashboard" /> 

    <!-- include Shadow below appbar --> 
    <View android:layout_width="match_parent" 
     android:layout_height="5dp" 
     android:background="@drawable/toolbar_dropshadow"/> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     xmlns:app="http://schemas.android.com/apk/res-auto"> 

     <RelativeLayout 
      android:id="@+id/relativemain_main" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent"> 


      <android.support.v7.widget.RecyclerView 
       android:id="@+id/recycler_view_tickets" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_alignParentTop="true" 
       android:layout_centerHorizontal="true" 
       android:scrollbars="none" /> 

     </RelativeLayout> 



     <fragment 
      android:id="@+id/fragment_navigation_drawer" 
      android:layout_width="@dimen/navdrawer_width" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      app:layout = "@layout/fragment_navigation_drawer" 
      android:name="baman.lankahomes.lk.zupportdeskticketsystem.Data.navigationDrawerFragment" 
      tools:layout="@layout/fragment_navigation_drawer" /> 

    </android.support.v4.widget.DrawerLayout> 

</LinearLayout> 

應用欄儀表板

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



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

儀表板式類

public class Dashboard extends AppCompatActivity { 
    private Toolbar toolbar; 
    public DrawerLayout drawerLayout; 
    public ListView drawerList; 
    private navigationDrawerFragment drawerFragment; 
    List<TicketsItemObject> items = new ArrayList<TicketsItemObject>(); 

    private RecyclerView recyclerView; 
    private LinearLayoutManager layoutManager; 
    private TicketsRecyclerViewAdapter adapter; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setTitle("Dashboard"); 
     setContentView(R.layout.activity_dashboard); 

     applicationEnvironment = new ApplicationEnvironmentURL(this.context); 
     context = this.getApplicationContext(); 

     toolbar = (Toolbar) findViewById(R.id.app_bar_dashboard); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayShowHomeEnabled(true); 

     drawerFragment = (navigationDrawerFragment) 
       getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer); 
     drawerFragment.setup(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), toolbar); 

清單

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="baman.lankahomes.lk"> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity 
      android:name=".Login" 
      android:screenOrientation="portrait"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".Signup" /> 
     <activity 
      android:name=".ForgotPassword" 
      android:label="@string/forgotpass" /> 
     <activity 
      android:name=".CompanyProfile" 
      android:label="@string/your_company_profile" /> 
     <activity 
      android:name=".Dashboard" 
      android:launchMode="singleInstance" /> 
     <activity 
      android:name=".NewTicket" 
      android:launchMode="singleInstance" /> 
     <activity android:name=".Tickets" /> 
     <activity 
      android:name=".TicketDetails" 
      android:launchMode="singleInstance" /> 
     <activity 
      android:name=".TicketResponse" 
      android:launchMode="singleInstance" /> 
     <activity 
      android:name=".AddNote" 
      android:launchMode="singleInstance" /> 
     <activity android:name=".Notifications" 
      android:launchMode="singleInstance" ></activity> 
    </application> 

</manifest> 
+1

嘗試將textview的顏色從白色更改爲任何其他顏色! – Piyush

+2

檢查您的值-21/style.xml –

回答

0

嘗試使用:

getSupportActionBar().setDisplayShowTitleEnabled(true); 
getSupportActionBar().setTitle("Your title"); 
+1

Hy tnx。但得到錯誤'java.lang.RuntimeException:無法啓動活動ComponentInfo {baman.lankahomes.lk.zupportdeskticketsystem/baman.lankahomes.lk.zupportdeskticketsystem.Dashboard}:java.lang.NullPointerException:嘗試調用虛擬方法'void android.support.v7.app.ActionBar.setTitle(java.lang.CharSequence)'在一個空對象引用上' –

+0

確保在你已經導入的活動中:「android.support.v7.widget.Toolbar」? AppTheme,你可以嘗試強烈設置爲'Theme.AppCompat.Light.NoActionBar'。 – alway5dotcom

0
getSupportActionBar().setTitle("title"); 

會做的伎倆。

0

我認爲你需要設置標題之後您調用:

setSupportActionBar(toolbar); 

,然後使用:

getSupportActionBar().setTitle("title"); 

作爲設置標題的方法。