wrap_content或match_parent,而不是固定的數(shù)值setSupportActionBar設(shè)置tool bar,getSupportActionBar可以返回一個(gè)ActionBar對象(盡管設(shè)置的是tool bar),可以對app bar進(jìn)行相關(guān)操作onOptionsItemSelected回調(diào)中getSupportActionBar().setDisplayHomeAsUpEnabled(true);;如此設(shè)置之后就無需在代碼中進(jìn)行響應(yīng)操作了;onDraw函數(shù)中進(jìn)行自定義繪制onSizeChanged函數(shù)中響應(yīng)尺寸的變化,layout的變化onLayout, onMeasure等onTouchEventTouchEvent的信息比較原始,通??梢允褂孟到y(tǒng)提供的幫助類提供的高級API:GestureDetectorScroller,動(dòng)畫等方式,以達(dá)到真實(shí)世界的物理運(yùn)動(dòng)效果...
API 14+,讓status bar可見性為gone,指定theme為@style/Theme.AppCompat.Light.NoActionBar.FullScreen或者@android:style/Theme.Holo.NoActionBar.Fullscreen
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
API 14+,讓navigation bar可見性為gone
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
decorView.setOnSystemUiVisibilityChangeListener,監(jiān)聽system ui可見性變化,在可見時(shí),通過postDelayed,再次隱藏之;SYSTEM_UI_FLAG_IMMERSIVE和SYSTEM_UI_FLAG_IMMERSIVE_STICKY,前者同樣存在上述問題;FullscreenActivity模板;響應(yīng)system ui可見性的變化
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
}
}
});
更多參見material design專題,包括:
兼容性維護(hù):