1. 两个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如下(两个透明设置)::
<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
//设置彩色状态栏
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintResource(R.color.colorPrimaryDark);
tintManager.setStatusBarTintEnabled(true);
//设置Anctionbar
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar_floatview);
setSupportActionBar(mToolbar);
4. 对4.4版本的下移进行处理
使用以上配置在4.4下会整体上移一个systembar的高度,需要在OnCreate方法中加入如下代码:
//4.4系统下移一个状态栏高度
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方法通过反射获取SystemBar的高度:
// 通过反射获取状态栏高度
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()