距离传感器(ProximitySensor)
P-Sensor距离感应器,可以感应手机和人体距离。具体使用用途是在通话过程中打开P-Sensor,那么当手机屏幕贴近用户脸部时,就会自动感应出手机和人体距离是多少。当小于某一个值时,就会熄灭屏幕,不再接收用户触摸屏幕事件,从而有效的防止通话过程中误触摸事件的出现。
例子1:利用按钮实现切换背景颜色
XML文件
<LinearLayout 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"
tools:context="${relativePackage}.${activityClass}"
android:orientation="vertical"
>
<TextView
android:id="@+id/tv_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="通过按钮改变背景颜色"
android:textSize="50sp"
android:background="#aaff0000"
android:layout_weight="1"
android:gravity="center"
/>
<Button
android:id="@+id/btn_change_color"
android:layout_width="match_parent"
a