Android之贴图-----

今天学习了一点关于如何美化界面的知识,感觉其中的新知识蛮多,也蛮使用:

下面看效果图,虽然不好看,但是却可以实现我们平时难以做到的功能:



注意第二个对话框是用的一个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的样式就改变了


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值