2016-12-27 7 views
1

please check the image that shows the displayed output Ich habe eine Fragmentklasse erstellt und in ihrem XML-Layout habe ich eine Symbolleiste mit etwas Text hinzugefügt. Aber aus irgendeinem Grund wird dort auch der Name der App angezeigt. Ich habe auch andere Seiten mit demselben Code gemacht, aber der Name wird nur auf diesem angezeigt.Warum wird der App-Name in der Toolbar angezeigt?

Hier ist mein xml-Code:

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

<android.support.v7.widget.Toolbar 
    android:id="@+id/my_toolbar1" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

    <TextView 
     android:text="Recharges" 
     android:textAppearance="@style/Base.TextAppearance.AppCompat.Large" 
     android:textColor="#ffffff" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/textView1" 
     android:layout_weight="1" /> 

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


<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:srcCompat="@drawable/logo" 
    android:id="@+id/imageView3" /> 

<GridLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:columnCount="2" 
    android:rowCount="5"> 



    <ImageView 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:layout_marginTop="25dp" 
     android:layout_marginRight="10dp" 
     android:layout_row="1" 
     android:layout_column="0" 
     app:srcCompat="@drawable/mobile" 
     android:id="@+id/imageView4" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_row="1" 
     android:gravity="center" 
     android:layout_column="1" 
     android:layout_marginTop="30dp" 
     android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" 
     android:text="Mobile"/> 

    <ImageView 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:layout_marginTop="25dp" 
     android:layout_row="2" 
     android:layout_column="0" 
     app:srcCompat="@drawable/tv" 
     android:id="@+id/imageView" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_row="2" 
     android:layout_column="1" 
     android:layout_marginTop="30dp" 
     android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" 
     android:text="DTH"/> 

    <ImageView 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:layout_marginTop="25dp" 
     android:layout_row="3" 
     android:layout_column="0" 
     app:srcCompat="@drawable/data" 
     android:id="@+id/imageView8" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_row="3" 
     android:layout_column="1" 
     android:layout_marginTop="30dp" 
     android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" 
     android:text="DataCard"/> 

     /> 




</GridLayout> 

+0

Sie android hinzugefügt haben: theme = "@ style/ThemeOverlay.AppCompat.ActionBar" dieses Thema auf anderen Seiten auch? –

+0

ja dieses Problem war ursprünglich nicht da, es kam nach dem Grid-Layout-Code. –

+1

versuchen Sie, toolbar.setTitle ("Lädt") zu verwenden; in deinem Java-Code. Es ist nicht nötig extra TextView zu benutzen. –

Antwort

0

In Ihrer Code - android:theme="@style/ThemeOverlay.AppCompat.ActionBar"

Änderung über die Linie zu:

app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 

Dann wird der Titel in weißer Farbe angezeigt.

Toolbar ersetzen Code mit diesem:

<android.support.v7.widget.Toolbar 
    android:id="@+id/my_toolbar1" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

In Java:

final Toolbar toolbar = (Toolbar) view.findViewById(R.id.my_toolbar1); 
toolbar.setTitle("Recharges"); 
0

Zur Zeit statt Hinzufügen einiger Code in jede Aktivität oncreate() können Sie ein Etikett für jede Aktivität im AndroidManifest.xml zu speichern hinzufügen und es wird automatisch zur Symbolleiste hinzugefügt. Ex:

<activity 
     android:name="com.example.Activity" 
     android:label="@string/app_name" 
     android:screenOrientation="landscape"/> 
0

versuchen Sie dies:

in Ihren fragment

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    // Inflate the layout resource that'll be returned 
    View rootView = inflater.inflate(R.layout.fragment_home, container, false); 
    mToolbar = (Toolbar) rootView.findViewById(R.id.my_toolbar1); 
    if (mToolbar != null) { 
     ((AppCompatActivity)getActivity()).setSupportActionBar(mToolbar); 
    } 
    mToolbar.setTitle("Text Title"); 

    return rootView; 
} 
Verwandte Themen