Q1:有没有人设法在xml选择器中使用自定义字符串/枚举属性?我通过以下[1]获得了一个布尔属性,但不是字符串属性.
编辑:谢谢你的回答.目前android仅支持布尔选择器.请参阅接受的答案.
我打算实现一个复杂的自定义按钮,其外观取决于两个变量.其他将是布尔属性(true或false)和另一个类别属性(具有许多不同的可能值).我的计划是使用布尔和字符串(或枚举?)属性.我希望我可以使用boolean和string属性在xml选择器中定义UI.
Q2:为什么在[1]中onCreateDrawableState(),布尔属性只有在它们为真时才合并?
注意:这只是一个测试应用程序,用于确定xml选择器中是否可以使用string/enum属性.我知道我可以在没有自定义属性的情况下设置按钮的textcolor.
在我的演示应用程序中,我使用布尔属性将按钮背景设置为dark/bright和string属性以设置文本颜色,{"red","green","blue"}之一.属性定义在/res/values/attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyCustomButton">
<attr name="make_dark_background" format="boolean" />
<attr name="str_attr" format="string" />
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)
以下是我想要实现的选择器:
@ drawable/custom_button_background(有效)
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.customstringattribute">
<item app:make_dark_background="true" android:drawable="@color/dark" />
<item android:drawable="@color/bright" />
</selector>
Run Code Online (Sandbox Code Playgroud)
@ color/custom_button_text_color(不起作用)
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.customstringattribute">
<item app:str_attr="red" android:color="@color/red" />
<item app:str_attr="green" android:color="@color/green" />
<item app:str_attr="blue" android:color="@color/blue" />
<item android:color="@color/grey" />
</selector>
Run Code Online (Sandbox Code Playgroud)
以下是自定义按钮背景如何连接到布尔选择器,文本颜色连接到字符串选择器.
<com.example.customstringattribute.MyCustomButton
...
android:background="@drawable/custom_button_background"
android:textColor="@color/custom_button_text_color"
...
/>
Run Code Online (Sandbox Code Playgroud)
以下是init()方法中如何加载属性:
private void init(AttributeSet attrs) {
TypedArray …Run Code Online (Sandbox Code Playgroud) # 2x3 dimensional list
multidim_list = [
[1,2,3],
[4,5,6],
]
# 2x3x2 dimensional list
multidim_list2 = [
[
[1,2,3],
[4,5,6],
],
[
[7,8,9],
[10,11,12],
]
]
def multiply_list(list):
...
Run Code Online (Sandbox Code Playgroud)
我想实现一个函数,它将列表中的所有元素乘以2.但是我的问题是列表可以有不同的维度.
是否存在循环/迭代多维列表的一般方法,例如将每个值乘以2?
编辑1:谢谢你的快速答案.对于这种情况,我不想使用numpy.递归似乎很好,它甚至不需要复制列表,实际上可能非常大.
我想使用gVim在拆分窗口中查看pdf文件,是否有人知道这是否可行?怎么样?
一些细节:我刚刚开始使用vim并用它来做笔记,同时阅读pdf.我写自己的笔记,但我经常从pdf复制文本,所以顺利复制会很好.目前我需要alt + tab for pdf viewer,转到鼠标或箭头键,选择文本,复制,alt + tab返回vim.当然这不是一项艰巨的任务,但使用vim我觉得没有鼠标就可以实现,将手放在"主行",而不需要外部程序alt + tab ...
理想情况下,我希望显示pdf,因为它应该是.如果那是不可能的,我将尝试使用一些插件将pdf显示为文本表示.