今天在写安卓的时候,需要设置一个对话框Dialog,但是发现有的TextView中的文字居然显示不出来。
当时现场:
我设计的样式是这样的!

弹出来的样子是这样的 !

当时的xml代码是这样的!(展示第一行的布局)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开具药物"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_selectedMedicine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="创可贴"
android:textColor="#000000"
android:textSize="18sp" />
<!-- 创建一个是选择药物的spinner -->
<Spinner
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" />
</LinearLayout>
很明显,当时里面有很多个TextView,但是只有一个TextView的文字显示出来了,其他控件(spinner和EditText)中文字都没有显示出来。他的控件是加载出来的,因为控件并没有发生位移,而且EditText的下划线也显示了出来。
还好有一个TextView控件的文字显示出来了,我就对比两个控件之间的区别,最终发现只要加了TextColor就可以显示出来。不管TextColor加的是什么颜色都可以显示出来了。
在安卓开发中遇到Dialog的TextView文字显示不出来的问题,通过对比显示正常与不正常的TextView,发现设置TextColor即可解决问题,即使颜色任意。
10万+

被折叠的 条评论
为什么被折叠?



