Android studio中自定义控件在Android Studio中xmlns不识别问题

来源:互联网 发布:淘宝网mac版客户端 编辑:程序博客网 时间:2024/05/16 10:52

Gradle工具会自动识别,所以不用指定包名



xmlns:xx="http://schemas.android.com/apk/res/com.xxx"
换成

xmlns:xx="http://schemas.android.com/apk/res-auto"然后同步一下,那个XX就是自定义控件自己设定的属性

例如下面的其中 ratingbar就是自定义属性,

<com.abct.tljr.ui.widget.RatingBar    android:id="@+id/layout_main_recommend_item_star_bar"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    ratingbar:clickable="false"    ratingbar:starCount="5"    android:layout_below="@+id/tv_level"    android:layout_marginLeft="15dp"    android:layout_alignLeft="@id/tv_name"    ratingbar:starEmpty="@drawable/img_xingxing3"    ratingbar:starFill="@drawable/img_xingxing1"    ratingbar:starHalf="@drawable/img_xingxing2"    ratingbar:starImageSize="25dp"    />

所以要在自定义控件所在的xml中的根布局中做出如下的属性设置


<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"              xmlns:ratingbar="http://schemas.android.com/apk/res-auto"              android:layout_width="match_parent"              android:layout_height="wrap_content"              android:background="@color/white"              android:orientation="vertical">



0 0
原创粉丝点击