2016年2月18日、19日に開催された Droid Kaigi 2016 で講演してきました。
スタッフの皆様、講演を聞きに来てくれた参加者のみなさま、ありがとうございました。
需要の高そうな StatusBar の透明化については別途ブログのエントリーにしました。
StatusBar 透明化の正しい方法 : Y.A.M の雑記帳
2016年2月19日金曜日
StatusBar 透明化の正しい方法
各属性についての説明や、なぜこのような設定になっているのかは Droid Kaigi 2016 の発表資料の 121p 以降 を参照してください。
values/styles.xml
上記のような指定を行うと次のような見た目になります。
4.3以下
4.4
5系
6系
values/styles.xml
<resources>
<style name="Theme.AppTheme.TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar" />
</resources>
values-v19/styles.xml
<resources>
<style name="Theme.AppTheme.TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
values-v21/styles.xml
<resources>
<style name="Theme.AppTheme.TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
values-v23/styles.xml
<resources>
<style name="Theme.AppTheme.TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">true</item>
</style>
</resources>
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
findViewById(android.R.id.content).setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
setContentView(R.layout.activity_splash);
}
}
<activity
android:name=".SplashActivity"
android:theme="@style/Theme.AppTheme.TranslucentStatusBar" />
上記のような指定を行うと次のような見た目になります。
4.3以下
4.4
5系
6系
2016年2月2日火曜日
Theme.NoDisplay は onCreate() で finish() する Activity 以外で使うと Android 6.0 でクラッシュする
Issue 2353: Activity crash with @android:style/Theme.NoDisplay : android-developer-preview
Android 6.0 から onCreate() で finish() していない Activity に Theme.NoDisplay をセットすると startActivity() したときにクラッシュします。 Theme.Translucent や Theme.Translucent.NoTitleBar はクラッシュしません。クラッシュ時の Exception は IllegalStateException で、メッセージは did not call finish() prior to onResume() completing です。
この原因となるテーマ属性は windowNoDisplay です。デフォルトは false ですが、Theme.NoDisplay では true がセットされています。つまり
onCreate() で finish() していない Activity のテーマで windowNoDisplay が true だとクラッシュします。
次のように onCreate() で finish() していればクラッシュしません。
if set to true, and this window is the main window of an Activity, then it will never actually be added to the window manager. This means that your activity must immediately quit without waiting for user interaction, because there will be no such interaction coming.
とあるので、正しい挙動になったと言えるのでしょう。
- 関連
Android 6.0 から onCreate() で finish() していない Activity に Theme.NoDisplay をセットすると startActivity() したときにクラッシュします。 Theme.Translucent や Theme.Translucent.NoTitleBar はクラッシュしません。クラッシュ時の Exception は IllegalStateException で、メッセージは did not call finish() prior to onResume() completing です。
この原因となるテーマ属性は windowNoDisplay です。デフォルトは false ですが、Theme.NoDisplay では true がセットされています。つまり
onCreate() で finish() していない Activity のテーマで windowNoDisplay が true だとクラッシュします。
次のように onCreate() で finish() していればクラッシュしません。
public class NoDisplayActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
finish();
}
}
<activity android:name=".NoDisplayActivity"
android:theme="@android:style/Theme.NoDisplay" />
windowNoDisplay のドキュメントには
if set to true, and this window is the main window of an Activity, then it will never actually be added to the window manager. This means that your activity must immediately quit without waiting for user interaction, because there will be no such interaction coming.
とあるので、正しい挙動になったと言えるのでしょう。
- 関連
- FacebookActivity did not call finish() on Api 23+ : stack over flow
- Activity did not call finish? (API 23) : stack over flow
- https://commonsware.com/blog/2015/11/02/psa-android-6p0-theme.nodisplay-regression.html
登録:
投稿 (Atom)