2017-01-08 1 views
-2

現在、私のタイトルは新しいAndroidアプリケーションに集中させています。これはアンドロイドがアプリに割り当てた基本的なタイトル(画面の一番上)です。アプリケーションは、 "タブ付き"テンプレートを使用してAndroidスタジオで作成された非常にシンプルなクッキーカッター「タブ付き」アプリケーションです。Android用アプリケーション - センタータイトル

タイトルはシンプルテキスト(約30文字)です。 「デザイン」オプションを選択すると、タイトルはmain.xmlに表示されますが、編集することは不可能です。どんな助けもありがとうございます。以下は

は私のmain.xmlのコピーです:

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    tools:context="com.my.app.MainActivity"> 
    <item 
     android:id="@+id/action_settings" 
     android:layout_width="match_parent" 
     android:orderInCategory="100" 
     android:layout_gravity="center" 
     android:title="@string/action_settings" 
     app:showAsAction="never" /> 
</menu> 
+0

このコードはmenu.xmlではありませんか? –

答えて

0

同様

<android.support.v7.widget.Toolbar 
android:id="@+id/toolbar_top" 
android:layout_height="wrap_content" 
android:layout_width="match_parent" 
android:minHeight="?attr/actionBarSize" 
android:background="@color/action_bar_bkgnd" 
app:theme="@style/ToolBarTheme" > 


<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Your Title" 
    android:layout_gravity="center" 
    android:id="@+id/toolbar_title" /> 


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

以下のようにあなたは、私は、コードで遊んで後TextView

以下のような
TextView tv = (TextView) findViewById(R.id.toolbar_title); 
tv.setText("Your Text"); 
+0

ありがとうございました!あなたはまだデフォルトのタイトルをオフにする必要がありますが、これは私のコードを修正するために必要なものです:) – Purkey

+0

'getSupportActionBar()。setDisplayShowTitleEnabled(false);' – Jayanth

0

あなたが活動中のsetTitle( "私のタイトルを")を使用することができます。しかし、推奨していないので、中央に設定する方法はありません。しかし、あなたがまだそれを望むならば、あなたはスペースで埋めていくことができます。 (「私のタイトル」)

0

のテキストを設定できるカスタムToolBarを作成することができますツールバーのタイトルを変更する方法を理解しました。&ツールバータイトルのテキストを変更します。

最初に、Androidの提供するデフォルトのタイトルを無効にするアクティビティの "onCreate"を編集する必要があります。以下のサンプルを参照してください。

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayShowTitleEnabled(false); 

第2に、アプリケーションタイトルのツールバーXML(app:title = "your title")内の参照を削除する必要があります。 TextViewをツールバーXMLに追加する必要があります。 、私はタイトルを再作成していることが、上記のTextViewで

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_gravity="center" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:background="#67ccb2" 
    android:elevation="6dp" 
    android:minHeight="?attr/actionBarSize" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textStyle="bold" 
     android:textSize="22dp" 
     android:text="MY APP NAME" 
     android:layout_gravity="center" 
     android:id="@+id/toolbar_title" /> 
</android.support.v7.widget.Toolbar> 

お知らせそのテキストサイズを変更し、それは大胆作っ&は見た目真ん中(でそれを中心に:以下は私のために働いているコードのサンプルです驚くばかり)。

私はこれが誰かを助けることを望みます:)

関連する問題