2017-01-19 10 views
0

Ich benutze Actionbar und Anzeige einiger Titel und Untertitel der Aktionsleiste. Ich möchte, dass die Untertitelgröße kleiner als der Titel ist. Und ich habe auch ein Logo-Symbol in der linken Seite. Wie sollte ich die Ausrichtung anpassen?Actionbar Titel und Untertitel Ausrichtung und textSize in Fragmenten

Es gibt ein weiteres Fragment, in dem ich den Zurück-Button als Home-Button verwende. Daher möchte ich auch den Abstand zwischen der Zurück-Schaltfläche und dem Titel der Aktionsleiste reduzieren.

Ich habe versucht, diesen Code zu verwenden. Aber es hat nicht geholfen.

UserListFragment.java

View viewActionBar = getActivity().getLayoutInflater().inflate(R.layout.actionbar_layout, null); 
     ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,ActionBar.LayoutParams.MATCH_PARENT,Gravity.CENTER); 

TextView textviewTitle = (TextView) viewActionBar.findViewById(R.id.mytext); 
textviewTitle.setText("DemoIosAppDoctor"+"\n"+"Doctor"); 
actionBar.setCustomView(viewActionBar, params); 
actionBar.setDisplayShowCustomEnabled(true); 
actionBar.setDisplayShowTitleEnabled(false); 
} 

actionbar_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#ffffff" 
    android:id="@+id/mytext" 
    android:textSize="18sp" 
    android:layout_marginTop="5dp" 
    android:layout_marginLeft="-2dp"/> 

</LinearLayout> 

Antwort

0

vollständig ActionBar anzupassen, sollten Sie Toolbar in Design XML definieren und fügen Sie dort Komponente besitzen. und verwenden Sie dann wie dieses

Toolbar tb = (Toolbar) findViewById(R.id.toolbar); 
setSupportActionBar(tb); 

Verwendung XML wie folgt aus:

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:minHeight="?attr/actionBarSize" 
     android:theme="?attr/actionBarTheme"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 


      <TextView 
       android:id="@+id/textView7" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="TextView" /> 


      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

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

Hinweis: Sie haben diese Aktivität Thema zu setzen, wie NoActionBar wie folgt aus:

<activity 
      android:name=".YourActivity" 
      android:parentActivityName=".index.IndexActivity" 
      android:theme="@style/AppTheme.NoActionBar" /> 

Und Thema wie dieses :

<style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
     <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
     <item name="android:statusBarColor">@android:color/transparent</item> 
    </style> 
+0

Können Sie bitte einmal den XML-Code post.? – Rider

+0

ja, ich habe meine Antwort bearbeitet –

+0

Es gibt Fehler in setSupportActionBar und findViewById – Rider

Verwandte Themen