「已注销」 2013-10-24 01:26 采纳率: 50%
浏览 1793
已采纳

想让字体变色,但是代码报错,刚开始学,不知道哪的问题

Activity.xml中TextView的代码

<TextView
    android:id="@+id/textview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

package com.example.android_day001;

import java.util.Random;

import android.os.Bundle; import android.app.Activity; import
android.graphics.Color; import android.view.Menu; import
android.view.View; import android.view.View.OnClickListener; import
android.widget.TextView;

public class MainActivity extends Activity {

    @Override   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);         TextView textview;
        textview = (TextView) this.findViewById(R.id.textview);

        textview.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                Random random = new Random(255);
                textview.setTextColor(Color.rgb(random.nextInt(),
                        random.nextInt(), random.nextInt()));           }       });     }

List item

    @Override   public boolean onCreateOptiosMenu(Menu menu) {      //
Inflate the menu; this adds items to the action bar if it is
present.        getMenuInflater().inflate(R.menu.main, menu);       return
true;   }

}

编辑器在代码的textview.setTextColor();处报错

  • 写回答

1条回答 默认 最新

  • ll_0520 2013-10-24 01:53
    关注

    Color.rgb(random.nextInt(), random.nextInt(), random.nextInt())改为Color.rgb(random.nextInt(256), random.nextInt(256), random.nextInt(256))试试

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向