我正在尝试构建自定义的android视图并应用作为图层列表的背景drawable.
图层列表有两个项目:
这是可绘制的xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white"/>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="1dp" />
<stroke
android:width="2dp"
android:color="@color/background_green" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
自定义视图是Android.view.View中的一个类,除了所需的测量重载之外,它目前没有任何功能.
我正在活动布局中的视图定义中应用背景:
<view
android:layout_width="match_parent"
android:layout_height="300dp"
class="com.example.widget.TestView"
android:id="@+id/view2"
android:layout_gravity="center_horizontal"
android:background="@drawable/rect_sig_cap"
android:layout_margin="20dp" />
Run Code Online (Sandbox Code Playgroud)
我期待看到的是一个带有白色背景和绿色边框的视图.我在部署项目时实际看到的是带有黑色背景和绿色边框的视图.
有趣的是,它在Android Studio的设计器预览中正确显示.只有当我将它部署到一个呈现黑色的设备时.
我错过了一些明显的东西吗?
我正在尝试使用KVC来检索使用Core数据构建的自定义NSManagedObject实体的属性值.我在尝试访问几层深处的属性时遇到UnknownKeyException,而对于我的生活,我无法弄清楚为什么......
根实体称为"Catch".它有许多属性:权重,长度等.它还与另一个称为"物种"的实体有一对一的关系.Species有一个名称属性,定义为NSString.
所以:
//this will output the species name (i.e. "Brook Trout")
NSLog(@"Catch.species.name = %@", catch.species.name);
//this will throw a NSUnknownKeyException
NSLog(@"Catch.species.name = %@", [catch valueForKey:@"species.name"]);
//but this works...!?
Species *species = (Species*)[catch valueForKey:@"species"];
NSLog(@"Species.name = %@", species.name);
Run Code Online (Sandbox Code Playgroud)
具体的例外细节是:
*由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[valueForUndefinedKey:]:实体Catch不是密钥值编码兼容的密钥"species.name".
有谁比我更了解这些东西知道发生了什么事吗?
提前致谢!