2016-03-19 11 views
0

enter image description hereAndroidのアクションバー:中央にアクションボタンとタイトルの色を変更する

ここでいずれかがアクションバーに中央にアイコンの色とタイトルを変更する方法を私に提案することができますしてくださいpicがあります...

+0

"android.support.v7.widget.Toolbar"を使用して、あなたのようにActionBarをカスタマイズしてください。 – shobhan

+0

http://stackoverflow.com/a/12388200/3790150 – saeed

+0

カスタムアクションバーのレイアウトを作成する必要がある場合があり、アクションを表示カスタムとしてアクションバーに追加できます。 –

答えて

0

これを試してください:
必要に応じてパッドを変更してください。

<?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="wrap_content" 
    android:background="?attr/colorPrimary" 
    android:minHeight="@dimen/abc_action_bar_default_height_material"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="1" 
     > 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:src="@drawable/ic_edit" 

      /> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="ABC" 
      android:gravity="center" 
      android:layout_weight="1" 
      android:textColor="@android:color/white" 

      /> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:paddingRight="10dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:src="@drawable/ic_edit"/> 
    </LinearLayout> 
</android.support.v7.widget.Toolbar> 

enter image description here

+0

申し訳ありませんが、 –

+0

は何か問題がありますか? –

+0

はい私はそれを持っている方法を提案してください..... –

0

次のように試してみてください。

プロジェクトで新しいレイアウトcustom_toolbar.xmlを作成します。

上記ファイルに以下のコードを追加してください。

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


    <ImageView 
     android:id="@+id/imgLeft" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentLeft="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginLeft="10dp" 
     android:src="@drawable/ic_events" /> 

    <ImageView 
     android:id="@+id/imgRight" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentRight="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginRight="10dp" 
     android:src="@drawable/ic_action" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="10dp" 
     android:text="Test" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" /> 


</RelativeLayout> 

してから、ツールバーのXMLファイルにそのレイアウトを追加します。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/ColorPrimary" 
    android:elevation="4dp" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

    <include layout="@layout/custom_toolbar" /> 

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

が、これはあなたを助けることを願っています。

関連する問題