【问题标题】:My Android app is showing bounds of TextViews but the actual TextViews aren't visible, what should I do?我的 Android 应用程序显示 TextViews 的边界,但实际的 TextViews 不可见,我该怎么办?
【发布时间】:2017-05-01 20:48:02
【问题描述】:

这是我在我的 Android 应用中使用的代码,用于显示与某人的 BMI 相关的某些信息。

几分钟前,代码运行正常,一切都很完美,但由于我做了一些我不记得具体的更改,TextViews 没有显示,我不知道为什么,我只是一个初学者。你对这个问题有什么想法吗?

似乎文本视图在那里,因为当我在开发人员选项中打开显示边界时,边界正在按预期显示,但我不知道出了什么问题。

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:clipToPadding="false"
android:layout_marginTop="16dp"
android:background="@color/transparent"
android:id="@+id/result_parent">
<TextView
android:id="@+id/result_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:elevation="10dp"
android:paddingBottom="8dp"
android:gravity="center_horizontal"
android:textColor="#ffffff"
android:textSize="34sp" />
<TextView
android:id="@+id/category_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:elevation="10dp"
android:layout_marginTop="16dp"
android:gravity="center_horizontal"
android:textColor="#ffffff"
android:textSize="34sp" />
</LinearLayout>

【问题讨论】:

  • 您可以发布您的活动代码吗?
  • 你的文字颜色是白色的,根据你的布局或主题的背景颜色需要合适,如果你的背景主题也是白色的,那么它不会显示相同颜色的原因

标签: java android xml textview android-elevation


【解决方案1】:

问题是您已将 textview 的颜色设置为白色,并带有以下行:并且您的背景也可能是白色的。

android:textColor="#ffffff"

把它改成别的东西:

android:textColor="#000000"

【讨论】:

  • result_container.setBackgroundColor(ContextCompat.getColor(this, R.color.zero)); result.setTextColor(ContextCompat.getColor(this, R.color.zero)); category.setTextColor(ContextCompat.getColor(this, R.color.zero)); category.setText("请在上方输入您的身高体重!");
  • 但问题是,即使我使用了前面评论中给出的java代码,被线性布局包围的整个区域都被单一的纯色覆盖,就好像线性布局已经放在了顶部,顺便说一句 R.color.zero 有点棕色
  • 我还需要说什么?任何想法
  • 我用白色值替换了 R.color.transparent 和 Color.TRANSPARENT 的每个值,现在这对我有用!感谢您的帮助
猜你喜欢
  • 2015-10-24
  • 2022-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-25
相关资源
最近更新 更多