Android 布局中的锁定符号
我一直试图在Android 布局中的锁定符号,android,unicode,textview,Android,Unicode,Textview,我一直试图在活动的文本视图中添加一个。 然而,我在这个网站上使用的东西似乎不起作用 <TextView android:id="@+id/lockTextView" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="\uD83D\uDD12"/> 编辑 正如您从我的示例中看到的,我希望将锁符号的“unicode”表示形式设
活动的文本视图中添加一个。
然而,我在这个网站上使用的东西似乎不起作用
<TextView
android:id="@+id/lockTextView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="\uD83D\uDD12"/>
编辑
正如您从我的示例中看到的,我希望将锁符号的“unicode”表示形式设置为xml中“TextView”中的文本。但是,显示锁定符号的唯一方法是在代码中设置它
我正在寻找一种在xml中实现这一点的方法,或者解释为什么这种方法与在代码中设置不同。您可以通过以下方式添加drawable
txtview.setCompoundDrawablesWithIntrinsicBounds(R.drawable.image, 0, 0, 0);
您还可以使用xml
<TextView
android:id="@+id/id_locText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableLeft="@drawable/img_lock"
android:drawablePadding="5dp"
android:singleLine="true"
android:text="@string/name"/>
对于编程方式:尝试使用以下更新的代码
将java中的Unicode字符添加到XML文件中的字符串:
String str = "\uD83D\uDD12" + getContext().getString(R.string.your_string);
我不想要图像。我希望unicode表示有效。从代码中设置此字符有效。但是我想从xml设置它。你的字体支持那个符号吗?ascii不支持该符号@Elango我用复选标记(\u2713)做了类似的事情。我原以为锁符号会使用相同的格式。但它没有。请检查@Elango我曾期望类似于行人的东西。那么,我在哪里可以检查我的锁定标记是否被允许?您可以更改您的字体,哪一种字体支持该符号。
String str = "\uD83D\uDD12" + getContext().getString(R.string.your_string);