• 每日日报2021.4.8


    今天完成内容:

    学习andriod checkbox

    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tab"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TableRow>
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="喜欢的颜色:"/>
    <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_gravity="clip_horizontal">
    <CheckBox
    android:id="@+id/box1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="红色"
    android:textColor="@color/chocolate"
    android:checked="true"/>
    <CheckBox
    android:id="@+id/box2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="蓝色" />
    <CheckBox
    android:id="@+id/box3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="绿色" />
    </LinearLayout>
    </TableRow>
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:id="@+id/show"/>
    </TableLayout>

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tab"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TableRow>
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="喜欢的颜色:"/>
    <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_gravity="clip_horizontal">
    <CheckBox
    android:id="@+id/box1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="红色"
    android:textColor="@color/chocolate"
    android:checked="true"/>
    <CheckBox
    android:id="@+id/box2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="蓝色" />
    <CheckBox
    android:id="@+id/box3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="绿色" />
    </LinearLayout>
    </TableRow>
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:id="@+id/show"/>
    </TableLayout>

    <color name="chocolate">#D2691E</color><!--巧可力色 →
    <color name="black">#000000</color><!--黑色 -->
    <color name="chocolate">#D2691E</color><!--巧可力色 →
    <color name="black">#000000</color><!--黑色 -->

    public class MainActivity extends Activity{
    private TextView show;
    private CheckBox box1,box2,box3;
    private String love= "我喜欢色是";
    private String not= "不是我喜欢的";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_layout);
    show = (TextView) findViewById(R.id.show);
    box1 = (CheckBox) findViewById(R.id.box1);
    box2 = (CheckBox) findViewById(R.id.box2);
    box3 = (CheckBox) findViewById(R.id.box3);
    box1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if(isChecked){
    if(show.getVisibility()==View.VISIBLE){
    show.setText(love+box1.getText());
    textColor();
    }else {
    show.setVisibility(View.VISIBLE);
    show.setText(love+box1.getText());
    textColor();
    }
    }else{
    show.setText(not);
    setTextBlack();
    }
    }
    });

    //box2 and box3 和box1的写法一样,在这就不重复写了;


    private void textColor() {
    box3.setTextColor(getApplicationContext().getColor(R.color.chocolate));
    }
    private void setTextBlack() {
    box3.setTextColor(getApplicationContext().getColor(R.color.black));
    }
    }
    }

    看视频

    遇到问题:

    明日目标:

    学习Android studio的开发

  • 相关阅读:
    HDU 2414 Chessboard Dance (力模拟)
    hdu2571命
    【玩转微信公众平台六】 构建新浪SAEserver
    【CTO辩论】移动创业大军:谁斗争or变更代理
    Swift语言iOS开发:CALayer十则示例
    小编辑 Java 中十进制和十六进制的相互转换
    RGB与HSB之间的转换公式
    YUV / RGB 格式及快速转换算法
    光学基础知识:白光、颜色混合、RGB、色彩空间
    关于HSL和HSV颜色空间的详细论述
  • 原文地址:https://www.cnblogs.com/leiyu1905/p/14912305.html
Copyright © 2020-2023  润新知