回答編集履歴

3

サンプルソース訂正

2017/10/22 13:02

投稿

keicha_hrs
keicha_hrs

スコア6768

test CHANGED
@@ -74,6 +74,8 @@
74
74
 
75
75
  activity_main.xml
76
76
 
77
+ (10/22 22:01 おかしな記述があったので訂正。結果に影響しないことは確認済。)
78
+
77
79
  ```XML
78
80
 
79
81
  <?xml version="1.0" encoding="utf-8"?>
@@ -88,6 +90,108 @@
88
90
 
89
91
  android:layout_height="match_parent"
90
92
 
93
+ tools:context=".MainActivity">
94
+
95
+
96
+
97
+ <android.support.v7.widget.Toolbar
98
+
99
+ android:id="@+id/toolbar"
100
+
101
+ android:layout_width="0dp"
102
+
103
+ android:layout_height="wrap_content"
104
+
105
+ android:layout_marginLeft="0dp"
106
+
107
+ android:layout_marginRight="0dp"
108
+
109
+ android:layout_marginTop="0dp"
110
+
111
+ android:background="?attr/colorPrimary"
112
+
113
+ android:minHeight="?attr/actionBarSize"
114
+
115
+ android:theme="?attr/actionBarTheme"
116
+
117
+ app:layout_constraintLeft_toLeftOf="parent"
118
+
119
+ app:layout_constraintRight_toRightOf="parent"
120
+
121
+ app:layout_constraintTop_toTopOf="parent" />
122
+
123
+
124
+
125
+ </android.support.constraint.ConstraintLayout>
126
+
127
+ ```
128
+
129
+
130
+
131
+ res/values/styles.xml
132
+
133
+ ```XML
134
+
135
+ <resources>
136
+
137
+
138
+
139
+ <!-- Base application theme. -->
140
+
141
+ <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
142
+
143
+ <!-- Customize your theme here. -->
144
+
145
+ <item name="colorPrimary">@color/colorPrimary</item>
146
+
147
+ <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
148
+
149
+ <item name="colorAccent">@color/colorAccent</item>
150
+
151
+ <item name="android:textColorPrimary">#FFFFFF</item>
152
+
153
+ <item name="android:textColor">#000000</item>
154
+
155
+ </style>
156
+
157
+
158
+
159
+ </resources>
160
+
161
+ ```
162
+
163
+
164
+
165
+ res/menu/menu_main.xmlやres/value/strings.xmlも若干触りましたが、大勢に影響あるものとは思えないので割愛。
166
+
167
+
168
+
169
+ 上記のコードを、デバイスをNexus 5Xにしたエミュレーターで動作させた結果が下図です。全角13文字まで表示されています。
170
+
171
+ ![](b541eec3f808dc6ecdca522e8c9ebcc7.png)
172
+
173
+
174
+
175
+ ---
176
+
177
+
178
+
179
+ (参考追記)
180
+
181
+ activity_main.xml(LinearLayout版)
182
+
183
+ ```XML
184
+
185
+ <?xml version="1.0" encoding="utf-8"?>
186
+
187
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
188
+
189
+ xmlns:tools="http://schemas.android.com/tools"
190
+
191
+ android:layout_width="match_parent"
192
+
193
+ android:layout_height="match_parent"
194
+
91
195
  android:orientation="vertical"
92
196
 
93
197
  tools:context=".MainActivity">
@@ -98,118 +202,14 @@
98
202
 
99
203
  android:id="@+id/toolbar"
100
204
 
101
- android:layout_width="0dp"
205
+ android:layout_width="match_parent"
102
206
 
103
207
  android:layout_height="wrap_content"
104
208
 
105
- android:layout_marginLeft="0dp"
106
-
107
- android:layout_marginRight="0dp"
108
-
109
- android:layout_marginTop="0dp"
110
-
111
209
  android:background="?attr/colorPrimary"
112
210
 
113
211
  android:minHeight="?attr/actionBarSize"
114
212
 
115
- android:theme="?attr/actionBarTheme"
116
-
117
- app:layout_constraintLeft_toLeftOf="parent"
118
-
119
- app:layout_constraintRight_toRightOf="parent"
120
-
121
- app:layout_constraintTop_toTopOf="parent" />
122
-
123
-
124
-
125
- </android.support.constraint.ConstraintLayout>
126
-
127
- ```
128
-
129
-
130
-
131
- res/values/styles.xml
132
-
133
- ```XML
134
-
135
- <resources>
136
-
137
-
138
-
139
- <!-- Base application theme. -->
140
-
141
- <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
142
-
143
- <!-- Customize your theme here. -->
144
-
145
- <item name="colorPrimary">@color/colorPrimary</item>
146
-
147
- <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
148
-
149
- <item name="colorAccent">@color/colorAccent</item>
150
-
151
- <item name="android:textColorPrimary">#FFFFFF</item>
152
-
153
- <item name="android:textColor">#000000</item>
154
-
155
- </style>
156
-
157
-
158
-
159
- </resources>
160
-
161
- ```
162
-
163
-
164
-
165
- res/menu/menu_main.xmlやres/value/strings.xmlも若干触りましたが、大勢に影響あるものとは思えないので割愛。
166
-
167
-
168
-
169
- 上記のコードを、デバイスをNexus 5Xにしたエミュレーターで動作させた結果が下図です。全角13文字まで表示されています。
170
-
171
- ![](b541eec3f808dc6ecdca522e8c9ebcc7.png)
172
-
173
-
174
-
175
- ---
176
-
177
-
178
-
179
- (参考追記)
180
-
181
- activity_main.xml(LinearLayout版)
182
-
183
- ```XML
184
-
185
- <?xml version="1.0" encoding="utf-8"?>
186
-
187
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
188
-
189
- xmlns:tools="http://schemas.android.com/tools"
190
-
191
- android:layout_width="match_parent"
192
-
193
- android:layout_height="match_parent"
194
-
195
- android:orientation="vertical"
196
-
197
- tools:context=".MainActivity">
198
-
199
-
200
-
201
- <android.support.v7.widget.Toolbar
202
-
203
- android:id="@+id/toolbar"
204
-
205
- android:layout_width="match_parent"
206
-
207
- android:layout_height="wrap_content"
208
-
209
- android:background="?attr/colorPrimary"
210
-
211
- android:minHeight="?attr/actionBarSize"
212
-
213
213
  android:theme="?attr/actionBarTheme" />
214
214
 
215
215
 

2

LinearLayout版

2017/10/22 13:01

投稿

keicha_hrs
keicha_hrs

スコア6768

test CHANGED
@@ -112,7 +112,7 @@
112
112
 
113
113
  android:minHeight="?attr/actionBarSize"
114
114
 
115
- android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
115
+ android:theme="?attr/actionBarTheme"
116
116
 
117
117
  app:layout_constraintLeft_toLeftOf="parent"
118
118
 
@@ -169,3 +169,55 @@
169
169
  上記のコードを、デバイスをNexus 5Xにしたエミュレーターで動作させた結果が下図です。全角13文字まで表示されています。
170
170
 
171
171
  ![](b541eec3f808dc6ecdca522e8c9ebcc7.png)
172
+
173
+
174
+
175
+ ---
176
+
177
+
178
+
179
+ (参考追記)
180
+
181
+ activity_main.xml(LinearLayout版)
182
+
183
+ ```XML
184
+
185
+ <?xml version="1.0" encoding="utf-8"?>
186
+
187
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
188
+
189
+ xmlns:tools="http://schemas.android.com/tools"
190
+
191
+ android:layout_width="match_parent"
192
+
193
+ android:layout_height="match_parent"
194
+
195
+ android:orientation="vertical"
196
+
197
+ tools:context=".MainActivity">
198
+
199
+
200
+
201
+ <android.support.v7.widget.Toolbar
202
+
203
+ android:id="@+id/toolbar"
204
+
205
+ android:layout_width="match_parent"
206
+
207
+ android:layout_height="wrap_content"
208
+
209
+ android:background="?attr/colorPrimary"
210
+
211
+ android:minHeight="?attr/actionBarSize"
212
+
213
+ android:theme="?attr/actionBarTheme" />
214
+
215
+
216
+
217
+ </LinearLayout>
218
+
219
+ ```
220
+
221
+
222
+
223
+ これでも見た目上の結果は全く同じでした。

1

コード詳細を掲載

2017/10/22 05:48

投稿

keicha_hrs
keicha_hrs

スコア6768

test CHANGED
@@ -7,3 +7,165 @@
7
7
 
8
8
 
9
9
  (表示できる文字数が少ないのは、恐らくToolbarの幅がwrap_contentとしてレイアウトされているためだろうと思いますが・・・)
10
+
11
+
12
+
13
+ ---
14
+
15
+
16
+
17
+ 何が起きているのかよくわからないので、「こうしたらこうなった」というコードだけ載せておきます。
18
+
19
+
20
+
21
+ MainActivity.java
22
+
23
+ ```Java
24
+
25
+ public class MainActivity extends AppCompatActivity {
26
+
27
+
28
+
29
+ @Override
30
+
31
+ protected void onCreate(Bundle savedInstanceState) {
32
+
33
+ super.onCreate(savedInstanceState);
34
+
35
+ setContentView(R.layout.activity_main);
36
+
37
+
38
+
39
+ String title = "あいうえおかきくけこさしすせそ";
40
+
41
+
42
+
43
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
44
+
45
+ toolbar.setTitle(title);
46
+
47
+ setSupportActionBar(toolbar);
48
+
49
+ if (getSupportActionBar() != null) {
50
+
51
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
52
+
53
+ }
54
+
55
+ }
56
+
57
+
58
+
59
+ @Override
60
+
61
+ public boolean onCreateOptionsMenu(Menu menu) {
62
+
63
+ getMenuInflater().inflate(R.menu.menu_main, menu);
64
+
65
+ return true;
66
+
67
+ }
68
+
69
+ }
70
+
71
+
72
+
73
+ ```
74
+
75
+ activity_main.xml
76
+
77
+ ```XML
78
+
79
+ <?xml version="1.0" encoding="utf-8"?>
80
+
81
+ <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
82
+
83
+ xmlns:app="http://schemas.android.com/apk/res-auto"
84
+
85
+ xmlns:tools="http://schemas.android.com/tools"
86
+
87
+ android:layout_width="match_parent"
88
+
89
+ android:layout_height="match_parent"
90
+
91
+ android:orientation="vertical"
92
+
93
+ tools:context=".MainActivity">
94
+
95
+
96
+
97
+ <android.support.v7.widget.Toolbar
98
+
99
+ android:id="@+id/toolbar"
100
+
101
+ android:layout_width="0dp"
102
+
103
+ android:layout_height="wrap_content"
104
+
105
+ android:layout_marginLeft="0dp"
106
+
107
+ android:layout_marginRight="0dp"
108
+
109
+ android:layout_marginTop="0dp"
110
+
111
+ android:background="?attr/colorPrimary"
112
+
113
+ android:minHeight="?attr/actionBarSize"
114
+
115
+ android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
116
+
117
+ app:layout_constraintLeft_toLeftOf="parent"
118
+
119
+ app:layout_constraintRight_toRightOf="parent"
120
+
121
+ app:layout_constraintTop_toTopOf="parent" />
122
+
123
+
124
+
125
+ </android.support.constraint.ConstraintLayout>
126
+
127
+ ```
128
+
129
+
130
+
131
+ res/values/styles.xml
132
+
133
+ ```XML
134
+
135
+ <resources>
136
+
137
+
138
+
139
+ <!-- Base application theme. -->
140
+
141
+ <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
142
+
143
+ <!-- Customize your theme here. -->
144
+
145
+ <item name="colorPrimary">@color/colorPrimary</item>
146
+
147
+ <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
148
+
149
+ <item name="colorAccent">@color/colorAccent</item>
150
+
151
+ <item name="android:textColorPrimary">#FFFFFF</item>
152
+
153
+ <item name="android:textColor">#000000</item>
154
+
155
+ </style>
156
+
157
+
158
+
159
+ </resources>
160
+
161
+ ```
162
+
163
+
164
+
165
+ res/menu/menu_main.xmlやres/value/strings.xmlも若干触りましたが、大勢に影響あるものとは思えないので割愛。
166
+
167
+
168
+
169
+ 上記のコードを、デバイスをNexus 5Xにしたエミュレーターで動作させた結果が下図です。全角13文字まで表示されています。
170
+
171
+ ![](b541eec3f808dc6ecdca522e8c9ebcc7.png)