繁体   English   中英

我的代码无法更改按钮文本颜色

[英]my code not change button text color

我正在使用日历应用程序,我正在检查button.get文本是否等于当前日期,将颜色更改为xxx,否则以黑色显示文本,但问题是按钮文本将显示相同的颜色,或者值是否为当前日期?

今天看到这张图片是7月29日

http://imgur.com/8fpjSaA

当我在上周单击时,29号鞋将以第二个按钮的颜色显示为粉红色再次显示粉红色的第二个按钮值,请参见此

http://imgur.com/YkbE8AS

public class HoyahCalendar extends Activity {

    public static String[][] a = new String[6][7];
    String  January="January";
    String  February="February";
    String  March="March";
    String  April="April";
    String  May="May";
    String  June="June";
    String  Jully="Jully";
    String  August="August";
    String  September="September";
    String  October="October";
    String  November="November";
    String  December="December";
    String  Monthname;


    Button e00;
    Button e01;
    Button e02;
    Button e03;
    Button e04;
    Button e05;
    Button e06;

    Calendar mCalendar = Calendar.getInstance();
    mYear = mCalendar.get(Calendar.YEAR);
    mMonth = mCalendar.get(Calendar.MONTH) + 1;
    mDay = mCalendar.get(Calendar.DAY_OF_MONTH);

    public void showOnScreen()
    {
        if (mMonth == 1) {
            Monthname="January";
        }
        else if (mMonth == 2) {
            Monthname="February";
        }
        else if (mMonth == 3) {
            Monthname="March";
        }
        else if (mMonth == 4) {
            Monthname="April";
        }
        else if (mMonth == 5) {
            Monthname="May";
        }
        else if (mMonth == 6) {
            Monthname="June";
        }
        else if (mMonth == 7) {
            Monthname="July";
        }
        else if (mMonth == 8) {
            Monthname="August";
        }
        else if (mMonth == 9) {
            Monthname="September";
        }
        else if (mMonth == 10) {
            Monthname="October";
        }
        if (mMonth == 11) {
            Monthname="November";
        }
        else if (mMonth == 12) {
            Monthname="December";
        }

        date_today.setText(Monthname + "  " +mYear);
        e00.setText("" + a[0][0]);

        if(e00.getText().toString().equals(String.valueOf(mDay)))
        // if(e00.getText().toString().equals(mDay))
        {
            e00.setTextColor(Color.parseColor("#FFBBFF"));
            Toast.makeText(this, "Button1 text equals!", Toast.LENGTH_SHORT).show();
        }
        e01.setText("" + a[0][3]);

        if(e01.getText().toString().equals(String.valueOf(mDay)))
        {
            e01.setTextColor(Color.parseColor("#FFBBFF"));
            Toast.makeText(this, "Button2 text equals!", Toast.LENGTH_SHORT).show();
        }

        e02.setText("" + a[0][2]);
        if(e02.getText().toString().equals(String.valueOf(mDay)))
        {
            e02.setTextColor(Color.parseColor("#FFBBFF"));
            Toast.makeText(this, "Button3 text equals!", Toast.LENGTH_SHORT).show();
        }
        else
        {
            e02.setTextColor(Color.parseColor("#000000"));
        }

        e03.setText("" + a[0][3]);
        if(Integer.parseInt(e03.getText().toString()) == mDay)
        {
            e03.setTextColor(Color.parseColor("#FFBBFF"));
            Toast.makeText(this, "Button4 text equals!", Toast.LENGTH_SHORT).show();
        }

        e04.setText("" + a[0][4]);
        if(e04.getText().toString().equals(String.valueOf(mDay)))
        {
            e04.setTextColor(Color.parseColor("#FFBBFF"));
            Toast.makeText(this, "Button5 text equals!", Toast.LENGTH_SHORT).show();
        }

        e05.setText("" + a[0][5]);
        if(e05.getText().toString().equals(String.valueOf(mDay)))
        {
            e05.setTextColor(Color.parseColor("#FFBBFF"));
            Toast.makeText(this, "Button6 text equals!", Toast.LENGTH_SHORT).show();
        }

        e06.setText("" + a[0][6]);
        if(e06.getText().toString().equals(String.valueOf(mDay)))
        {
            e06.setTextColor(Color.parseColor("#FFBBFF"));
            Toast.makeText(this, "Button7 text equals!", Toast.LENGTH_SHORT).show();
        }
    }


    public void CalculateCalendar(int month_no, int week_no, int month_days)
    {
        int i, s, targetRow = 0;
        int currentDay;
        if (this.mDay == 0) {
            currentDay= HoyahCalendar.mDay;
        } else {
            currentDay = this.mDay;
        }
        //String[][] a = new String[6][7];
        for (i=0;i<week_no;i++)
            HoyahCalendar.a[i/7][i%7] = "";

        for(i=week_no; i<week_no + month_days; i++) {
            s = i - week_no + 1;
            HoyahCalendar.a[i/7][i%7] = String.valueOf(s);
            if (s == currentDay && HoyahCalendar.currentIndex == -1) {
                HoyahCalendar.currentIndex = i/7;
            }
        }

        for (i=0; i<7;i++) {
            if (HoyahCalendar.a[HoyahCalendar.currentIndex][i] == null) {
                HoyahCalendar.a[0][i] = "";
            }else{
                HoyahCalendar.a[0][i] =
                    HoyahCalendar.a[HoyahCalendar.currentIndex][i];
            }
        }

        for(i=week_no+month_days; i<42; i++)
            HoyahCalendar.a[i/7][i%7] = "";
    }
}

如果不是当天,则必须将颜色重置为黑色。

因此,对于每个“如果”,您都必须在将颜色设置为黑色的地方添加一个“其他”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM