Android 是否可以为自定义视图创建建议?

Android 是否可以为自定义视图创建建议?,android,android-custom-view,Android,Android Custom View,我正在创建一个自定义视图,但我想向用户显示建议,就像其他android视图一样。我可以用自定义视图来做吗 例如: 可以在自定义视图的declare styleable标记中使用枚举格式显示自定义选项的自定义选项 首先,在attrs.xml文件中声明所需的属性,如下所示 <declare-styleable name="customView"> <attr name="customOption" format="enum&qu

我正在创建一个自定义视图,但我想向用户显示建议,就像其他android视图一样。我可以用自定义视图来做吗

例如:


可以在自定义视图的
declare styleable
标记中使用枚举格式显示自定义选项的自定义选项

首先,在attrs.xml文件中声明所需的属性,如下所示

<declare-styleable name="customView">
  <attr name="customOption" format="enum">
    <enum name="option1" value="0" />
    <enum name="option2" value="1" />
  </attr>
</declare-styleable>
const val OPTION_1 = 0 //for readability
const val OPTION_2 = 1 //for readability
var customOption = OPTION_1

init {
  paint.isAntiAlias = true
  setupAttributes(attrs)
}

private fun setupAttributes(attrs: AttributeSet?) {
  val typedArray = context.theme.obtainStyledAttributes(attrs, R.styleable.customView, 0, 0)
  customOption = typedArray.getInt(R.styleable.customView_customOption, OPTION_1.toInt())
}

可以在自定义视图的
declare styleable
标记中使用枚举格式显示自定义选项的自定义选项

首先,在attrs.xml文件中声明所需的属性,如下所示

<declare-styleable name="customView">
  <attr name="customOption" format="enum">
    <enum name="option1" value="0" />
    <enum name="option2" value="1" />
  </attr>
</declare-styleable>
const val OPTION_1 = 0 //for readability
const val OPTION_2 = 1 //for readability
var customOption = OPTION_1

init {
  paint.isAntiAlias = true
  setupAttributes(attrs)
}

private fun setupAttributes(attrs: AttributeSet?) {
  val typedArray = context.theme.obtainStyledAttributes(attrs, R.styleable.customView, 0, 0)
  customOption = typedArray.getInt(R.styleable.customView_customOption, OPTION_1.toInt())
}

我在说“values.xml:19:4:的无效值'null'时出错。必须是整数。“如何建议字符串值?@RahulSaliya您必须共享代码和崩溃日志,请提出新问题。”。如果可能,在GitHub上共享代码。这会更容易提供帮助。之所以会发生这种情况,是因为我正在尝试字符串以获取建议,而它只接受整数。为什么要使用字符串,枚举不应该存储字符串。我收到的错误是“values.xml:19:4:的值'null'无效。必须是整数。”如何建议字符串值?@RahulSaliya您必须共享您的代码和崩溃日志,提出新问题。如果可能,在GitHub上共享代码。这会更容易提供帮助。之所以会发生这种情况,是因为我正在尝试字符串以获取建议,而它只接受整数。为什么要使用字符串,枚举不应该存储字符串。