android 开发中我在activity.java中给.xml文件中的textview赋值,但是运行时不能显示出来。

liukangchao 2018-01-15 04:16:58
这是布局文件中的代码,主要看TextView节点
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.iss.kcliu_14cauc.helloworld.LoginActivity">

<TextView
android:id="@+id/tv_hello"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</android.support.constraint.ConstraintLayout>
这是activity.java中的代码
public class LoginActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
TextView helloText = (TextView) findViewById(R.id.tv_hello);
helloText.setText("你好,世界,噜噜噜");
helloText.setTextColor(0x00ff00);
helloText.setTextSize(30);
}
}

...全文
994 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
一纸荒年-and 2018-01-19
  • 打赏
  • 举报
回复
错误行:helloText.setTextColor(0x00ff00); java代码可以改为:helloText.setTextColor(Color.parseColor("#00ff00")); 或改为引用资源文件颜色值;
usecf 2018-01-15
  • 打赏
  • 举报
回复
把helloText.setTextColor(0x00ff00);注释掉看看

80,337

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧