2016-08-05 36 views
4

Hallo Anzeigen Ich habe eine einfache Anwendung und getestet auf Android 4.4.4 und höherApp bar Titel in Android 5.0 nicht und über

in 4.4.4 Kitkat erstellt - es funktioniert gut (ich kann den Titel sehen in die App-Leiste)

enter image description here

Aber wenn ich es auf android 5.0 testen und darüber, ist der Titel unsichtbar

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 Aktivität

<?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> 

App Bar Armaturenbrett

<?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> 

DashBoard Klasse

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); 

Manifest

<?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

Versuchen Sie die Farbe der Textansicht von weiß zu anderen zu ändern! – Piyush

+2

Überprüfen Sie Ihre Werte-21/style.xml –

Antwort

0

Versuchen zu verwenden:

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

Hy tnx. aber bekomme den Fehler 'java.lang.RuntimeException: Kann die Aktivität nicht starten ComponentInfo {baman.lankahomes.lk.zupportdeskticketsystem/baman.lankahomes.lk.zupportdeskticketsystem.Dashboard}: java.lang.NullPointerException: Versuch, virtuelle Methode 'void aufzurufen android.support.v7.app.ActionBar.setTitle (java.lang.CharSequence) 'auf eine Null-Objekt-Referenz' –

+0

stellen Sie sicher, in Aktivität, die Sie importiert haben: "android.support.v7.widget.Toolbar"? AppTheme Sie können versuchen, "Theme.AppCompat.Light.NoActionBar" zu setzen. – alway5dotcom

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

den Trick.

0

Ich glaube, Sie müssen Titel ein, nachdem Sie rufen:

setSupportActionBar(toolbar); 

und dann verwenden:

getSupportActionBar().setTitle("title"); 

als Einstellung Titel Methode.