v7包:1. 保证5.0以上和5.0以下控件效果一致
2.保证低版本样式和高版本样式一致 使用相同主题
https://blog.csdn.net/qq_31001287/article/details/60867484
<color name="colorPrimary">#17c782</color> //导航栏颜色
<color name="colorPrimaryDark">#17c782</color> //状态栏颜色
<color name="colorAccent">#17c782</color> //控件主题颜色
<color name="windowBackground">#d9d9d9</color> //默认界面背景颜色
<color name="textColorPrimary">#333333</color> //默认文字主题颜色
必须在5.0以上才起作用,material design5.0引入
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/srl"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.xm.recyclerviewsimple.TestActivity">
<!-- <ImageView
android:id="@+id/image_item_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
/>-->
<!-- 使用系统内置的Dialog:android.app.AlertDialog -->
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="41dp"
android:text="Button"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="87dp"
android:layout_marginStart="87dp"
android:onClick="showMessag"/>
<!-- 使用系统内置的CheckBox -->
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/button"
android:layout_alignRight="@+id/button"
android:layout_below="@+id/button"
android:layout_marginEnd="19dp"
android:layout_marginRight="19dp"
android:layout_marginTop="117dp"
android:text="CheckBox" />
<!--android.support.v7.widget.AppCompatEditText -->
<!-- android.support.v7.widget.AppCompatCheckBox-->
<!-- 使用系统内置的EditButton -->
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/checkBox"
android:layout_alignLeft="@+id/checkBox"
android:layout_alignStart="@+id/checkBox"
android:layout_marginBottom="43dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<!-- 5.0以下和5.0以上即使使用Widget.AppCompat.ProgressBar也是有区别,需要自定义 -->
<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/checkBox"
android:layout_alignStart="@+id/checkBox"
android:layout_below="@+id/checkBox"
android:layout_marginTop="10dp" />
</RelativeLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
4.4效果:
上图左边是4.4模拟器,右边是5.0模拟器,很显然样式相同,如何保证样式相同4.4下和5.0+,使用v7包下控件替换、
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/srl"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.xm.recyclerviewsimple.TestActivity">
<!-- <ImageView
android:id="@+id/image_item_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
/>-->
<!--android.support.v7.app.AlertDialog
public void showMessag(View view){
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("女朋友");
builder.setMessage("给我一个女朋友");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
}-->
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="41dp"
android:text="Button"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="87dp"
android:layout_marginStart="87dp"
android:onClick="showMessag"/>
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/button"
android:layout_alignRight="@+id/button"
android:layout_below="@+id/button"
android:layout_marginEnd="19dp"
android:layout_marginRight="19dp"
android:layout_marginTop="350dp"
android:text="CheckBox" />
<!--android.support.v7.widget.AppCompatEditText -->
<!-- android.support.v7.widget.AppCompatCheckBox-->
<android.support.v7.widget.AppCompatEditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/checkBox"
android:layout_alignLeft="@+id/checkBox"
android:layout_alignStart="@+id/checkBox"
android:layout_marginBottom="43dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<!-- 5.0以下和5.0以上即使使用Widget.AppCompat.ProgressBar也是有区别,需要自定义 -->
<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/checkBox"
android:layout_alignStart="@+id/checkBox"
android:layout_below="@+id/checkBox"
android:layout_marginTop="10dp" />
</RelativeLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
4.4模拟器和5.0模拟器效果一致