如何在 axml 中使用自定义文本视图? [英] How to use a custom textview in axml?

查看:45
本文介绍了如何在 axml 中使用自定义文本视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义文本视图,但找不到使用它的方法,我只找到了 java 的示例.但是 com.yournamespace.RotatedTextViewcom.yournamespace.RotatedTextViewRotatedTextView 不会被识别.

I created a custom text view, but I couldn't find a way to use it I only found examples for java. But com.yournamespace.RotatedTextView, com.yournamespace.RotatedTextView and RotatedTextView doesn't get recognised.

我已经创建了 attrs.xml 并添加了:

I've created attrs.xml and added:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="RotatedTextView">
    <attr name="customFont" format="string"/>
  </declare-styleable>
</resources>

没有帮助,自定义文本视图开始如下:

Didn't help, the custom text view starts like:

namespace First_android {

  public class RotatedTextView : TextView { }

任何想法或来源?

推荐答案

您应该在 .axml 文件中使用类似于以下代码的内容:

You should use something like the following code in the .axml file:

<First_android.RotatedTextView
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:text="Test"  />

这篇关于如何在 axml 中使用自定义文本视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆