Toolbarの使い方自体がおかしい感じがしますので、まずは下記ドキュメントを参照してみてはどうでしょうか?
アプリバーのセットアップ
(表示できる文字数が少ないのは、恐らくToolbarの幅がwrap_contentとしてレイアウトされているためだろうと思いますが・・・)
何が起きているのかよくわからないので、「こうしたらこうなった」というコードだけ載せておきます。
MainActivity.java
Java
1public class MainActivity extends AppCompatActivity {
2
3 @Override
4 protected void onCreate(Bundle savedInstanceState) {
5 super.onCreate(savedInstanceState);
6 setContentView(R.layout.activity_main);
7
8 String title = "あいうえおかきくけこさしすせそ";
9
10 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
11 toolbar.setTitle(title);
12 setSupportActionBar(toolbar);
13 if (getSupportActionBar() != null) {
14 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
15 }
16 }
17
18 @Override
19 public boolean onCreateOptionsMenu(Menu menu) {
20 getMenuInflater().inflate(R.menu.menu_main, menu);
21 return true;
22 }
23}
24
activity_main.xml
(10/22 22:01 おかしな記述があったので訂正。結果に影響しないことは確認済。)
XML
1<?xml version="1.0" encoding="utf-8"?>
2<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:app="http://schemas.android.com/apk/res-auto"
4 xmlns:tools="http://schemas.android.com/tools"
5 android:layout_width="match_parent"
6 android:layout_height="match_parent"
7 tools:context=".MainActivity">
8
9 <android.support.v7.widget.Toolbar
10 android:id="@+id/toolbar"
11 android:layout_width="0dp"
12 android:layout_height="wrap_content"
13 android:layout_marginLeft="0dp"
14 android:layout_marginRight="0dp"
15 android:layout_marginTop="0dp"
16 android:background="?attr/colorPrimary"
17 android:minHeight="?attr/actionBarSize"
18 android:theme="?attr/actionBarTheme"
19 app:layout_constraintLeft_toLeftOf="parent"
20 app:layout_constraintRight_toRightOf="parent"
21 app:layout_constraintTop_toTopOf="parent" />
22
23</android.support.constraint.ConstraintLayout>
res/values/styles.xml
XML
1<resources>
2
3 <!-- Base application theme. -->
4 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
5 <!-- Customize your theme here. -->
6 <item name="colorPrimary">@color/colorPrimary</item>
7 <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8 <item name="colorAccent">@color/colorAccent</item>
9 <item name="android:textColorPrimary">#FFFFFF</item>
10 <item name="android:textColor">#000000</item>
11 </style>
12
13</resources>
res/menu/menu_main.xmlやres/value/strings.xmlも若干触りましたが、大勢に影響あるものとは思えないので割愛。
上記のコードを、デバイスをNexus 5Xにしたエミュレーターで動作させた結果が下図です。全角13文字まで表示されています。
(参考追記)
activity_main.xml(LinearLayout版)
XML
1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:tools="http://schemas.android.com/tools"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent"
6 android:orientation="vertical"
7 tools:context=".MainActivity">
8
9 <android.support.v7.widget.Toolbar
10 android:id="@+id/toolbar"
11 android:layout_width="match_parent"
12 android:layout_height="wrap_content"
13 android:background="?attr/colorPrimary"
14 android:minHeight="?attr/actionBarSize"
15 android:theme="?attr/actionBarTheme" />
16
17</LinearLayout>
これでも見た目上の結果は全く同じでした。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/22 02:52
2017/10/22 05:03
2017/10/22 05:30 編集
2017/10/22 05:42
2017/10/22 05:45