今天学习了一点关于如何美化界面的知识,感觉其中的新知识蛮多,也蛮使用:
下面看效果图,虽然不好看,但是却可以实现我们平时难以做到的功能:
注意第二个对话框是用的一个Activity,只是对应的Theme.Dialog 主题,主题在mainfest文件里配置。当然这里主要是第一个Activity是三个widget构成:
Button,EditText,ImageView组成,都用到了Android贴图功能;
在res目录下面新建drawable文件夹并新建edit_bg.xml文件,选择shape(也可以select等,都有相对应的功能。),这个xml文件将做为一个图片存在。引用的时候直接R.drawable.edit_bg也可以。下面看
edit_bg.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 这个主要是设置填充颜色;实心 --> <solid android:color="#77ffffff" /> <!-- 描边 --> <stroke android:width="3dip" android:color="#775f5f5f" /> <!-- 圆角 --> <corners android:radius="15dip" /> <!-- 设置渐变效果 android:startColor和android:endColor分别为起始和结束颜色,ndroid:angle是渐变角度,必须为45的整数 倍。 另外渐变默认的模式为android:type="linear",即线性渐变,可以指定渐变为径向渐变,android:type="radial", 径向渐变需要指定半径android:gradientRadius="50"。 --> <gradient android:angle="45" android:endColor="#00ffffff" android:startColor="#77000000"> </gradient> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> </shape>这就想法于一个图片了,如果想设置EditText为这种试图,只需要设置EditText的背景为drawable/edit_bg即可.
下面看main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <Button android:id="@+id/btn_click" style="@style/buttonStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="click"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:textColor="@android:color/primary_text_light"/> <EditText android:id="@+id/et_test" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="hello,tietu" android:background="@drawable/edit_bg"/> <ImageView android:id="@+id/iv_test" android:src="@drawable/ic_launcher" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/edit_bg"/> </LinearLayout>也可以将这种edit_bg用于Activity的主题背景里面,这样Activity的样式就改变了