在Visual Studio 2017的Xamarin Android中设置按钮圆角及Drawable文件放置问题
解决Visual Studio 2017中Android项目Drawable文件的存放问题
别担心,我来帮你理清这个问题!在Visual Studio 2017的Android项目里,Drawable资源文件的存放位置是有固定路径的,具体步骤如下:
- 首先打开你的Android项目,在解决方案资源管理器中找到Resources文件夹并展开它
- 如果里面没有
drawable文件夹,右键点击Resources → 选择「添加」→「新建文件夹」,将文件夹命名为drawable(注意全小写,Android对资源文件夹的命名有严格要求) - 最后把你的
RoundShapeBtn.xml文件直接拖入这个新建的drawable文件夹就可以了
另外给你两个实用小提示:
- Android资源文件名推荐使用小写字母加下划线的规范(比如把
RoundShapeBtn.xml改成round_shape_btn.xml),避免出现不必要的编译问题 - 你的圆角按钮Shape代码是完全可用的:
<solid>标签用来设置按钮的背景填充色<corners>标签里的属性分别控制四个角的圆角半径,你这里设置了四个角都是10dp,刚好实现了全圆角的按钮效果
附你的Shape代码参考:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp"> <solid android:color="#6E6E6E"/> <!-- this one is ths color of the Rounded Button --> <corners android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" android:topLeftRadius="10dp" android:topRightRadius="10dp"/> </shape>
内容的提问来源于stack exchange,提问作者Niteesh Kumar
相关产品推荐
相关产品推荐

