1. 兩個(gè)style文件 style 和 style-v19
1.1style如下:
<resources>
<style name="Base.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="@style/Base.AppTheme">
</style>
<!-- Base application theme. -->
<style name="PayTheme" parent="@style/Base.AppTheme">
<item name="android:windowAnimationStyle">@style/activityAnimation</item>
</style>
<!-- animation 樣式 -->
<style name="activityAnimation" parent="@android:style/Animation">
<item name="android:activityOpenEnterAnimation">@anim/slide_right_in</item>
<item name="android:activityOpenExitAnimation">@anim/slide_left_out</item>
<item name="android:activityCloseEnterAnimation">@anim/slide_left_in</item>
<item name="android:activityCloseExitAnimation">@anim/slide_right_out</item>
</style>
<style name="Widget.CardContent" parent="android:Widget">
<item name="android:paddingLeft">16dp</item>
<item name="android:paddingRight">16dp</item>
<item name="android:paddingTop">24dp</item>
<item name="android:paddingBottom">24dp</item>
<item name="android:orientation">vertical</item>
</style>
<style name="MyEditText" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">@color/colorAccentLight</item>
<item name="colorControlActivated">@color/colorAccent</item>
</style>
</resources>
1.2style-V19如下(兩個(gè)透明設(shè)置)::
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<!--<item name="android:textColor">#FFFFFF</item>-->
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
2.頂層布局XML文件中加入屬性
android:fitsSystemWindows="true"
3. 使用systembarTintmanager
//設(shè)置彩色狀態(tài)欄
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintResource(R.color.colorPrimaryDark);
tintManager.setStatusBarTintEnabled(true);
//設(shè)置Anctionbar
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar_floatview);
setSupportActionBar(mToolbar);
4. 對(duì)4.4版本的下移進(jìn)行處理
使用以上配置在4.4下會(huì)整體上移一個(gè)systembar的高度,需要在OnCreate方法中加入如下代碼:
//4.4系統(tǒng)下移一個(gè)狀態(tài)欄高度
if(Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT)
{
RelativeLayout mDrawerLayout = (RelativeLayout)
findViewById(R.id.linearlayout_floatview);
mDrawerLayout.setPadding(0,
getStatusBarHeight(this.getApplicationContext()), 0, 0);
}
其中矾瘾,getStatusBarHeight方法通過(guò)反射獲取SystemBar的高度:
// 通過(guò)反射獲取狀態(tài)欄高度
public static int getStatusBarHeight(Context context) {
try {
Class<?> c = Class.forName("com.android.internal.R$dimen");
Object obj = c.newInstance();
Field field = c.getField("status_bar_height");
int x = Integer.parseInt(field.get(obj).toString());
return context.getResources().getDimensionPixelSize(x);
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
adsfasdfasdfasdf
int void main()