android - 为包含的布局 android 指定文本颜色

标签 android android-layout

我有一个用于几个不同地方的布局。

这个布局本身有一个 TextView 、一些按钮和一个进度条。

<LinearLayout id="reuse">
  <TextView/>
  <ProgressBar/>
  <Buttons/>
</LinearLayout>

// in other places

<include layout="reuse"/> // text color blue here

// in other places

<include layout="reuse" /> //text color gree here

现在,根据包含布局的位置,我想为 TextView 指定不同的文本颜色。

如何做到这一点?我尝试在包含中指定文本颜色似乎没有帮助?

最佳答案

我能想到的唯一方法是以编程方式进行,只需使用线性布局“重用”的引用,并使用 reuse.findViewById() 从中获取 textview 并自己操作属性。

关于android - 为包含的布局 android 指定文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40892668/

相关文章:

android - 是否有跨平台框架可以访问 Android、iOS 和 Windows Phone 的短信内容?

android - 小部件数据在运行繁重的应用程序时丢失

Android TableLayout 宽度问题

java - 仅在添加 WebView 和 TextView 时才在 LinearLayout 中动态创建 WebView 和 TextView

Android:如何为 ActionBar 中的项目自定义选择器?

android - Flask 到 android studio

java - 在 Android 中以编程方式设置 ToggleButton 的状态?

android - 以编程方式在 View 上添加填充

Android:创建自定义 3 状态切换按钮时出现问题

android - ListView 和列表 Activity