{"id":883,"date":"2017-03-07T18:06:44","date_gmt":"2017-03-07T10:06:44","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=883"},"modified":"2017-03-07T18:07:06","modified_gmt":"2017-03-07T10:07:06","slug":"android%e5%9f%ba%e7%a1%80%e6%8e%a7%e4%bb%b6checkbox%e4%b8%8eedittext%e7%9a%84%e5%9f%ba%e6%9c%ac%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/android\/2017\/03\/07\/180644883.html","title":{"rendered":"Android\u57fa\u7840\u63a7\u4ef6CheckBox\u4e0eEditText\u7684\u57fa\u672c\u4f7f\u7528"},"content":{"rendered":"<p>1\u3001\u4e0a\u56fe<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2017\/03\/20170307170905.jpg\" alt=\"\" width=\"360\" height=\"278\" class=\"alignnone size-full wp-image-884\" \/><\/p>\n<p>2\u3001Activity<\/p>\n<pre line=\"1\" lang=\"java\">package com.yusian.gamedemo;\n\nimport android.graphics.Typeface;\nimport android.support.v7.app.AppCompatActivity;\nimport android.os.Bundle;\nimport android.widget.CheckBox;\nimport android.widget.CompoundButton;\nimport android.widget.EditText;\n\npublic class MainActivity extends AppCompatActivity {\n    private EditText editText;\n    private int style = 0;      \/\/ \u5f53\u524d\u7c7b\u578b\uff0c\u5168\u5c40\u7528\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n        \/\/ \u6210\u5458\u53d8\u91cf\u8d4b\u503c\n        editText = (EditText)findViewById(R.id.editText);\n        \/\/ \u5c06\u4e24\u4e2aCheckBox\u5206\u522b\u7ed1\u5b9a\u4e8b\u4ef6\n        CheckBox box1 = (CheckBox)findViewById(R.id.checkbox1);\n        box1.setOnCheckedChangeListener(new CheckBoxListener());\n        CheckBox box2 = (CheckBox)findViewById(R.id.checkbox2);\n        box2.setOnCheckedChangeListener(new CheckBoxListener());\n    }\n    \/\/ \u5185\u90e8\u7c7b\u5b9e\u73b0CheckBox\u7684\u4e8b\u4ef6\u76d1\u542c\u63a5\u53e3\n    class CheckBoxListener implements CompoundButton.OnCheckedChangeListener{\n        @Override\n        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {\n            switch (buttonView.getId()){\n                \/\/ \u7b2c\u4e00\u4e2aCheckBox\u4e8b\u4ef6\u54cd\u5e94\n                case R.id.checkbox1:{\n                    \/\/ \u5982\u679cisChecked\u4e3atrue\u5219+ITALIC\uff0c\u5426\u5219-ITALIC\n                    style += (isChecked ? 1 : -1) * Typeface.ITALIC;\n                }break;\n                \/\/ \u7b2c\u4e8c\u4e2aCheckBox\u4e8b\u4ef6\u54cd\u5e94\n                case R.id.checkbox2:{\n                    \/\/ \u5982\u679cisChecked\u4e3atrue\u5219+BOLD\uff0c\u5426\u5219-BOLD\n                    style += (isChecked ? 1 : -1) * Typeface.BOLD;\n                }break;\n                default:break;\n            }\n            \/\/ \u5c06style\u8bbe\u7f6e\u5230EditText\u4e0a\n            editText.setTypeface(Typeface.DEFAULT, style);\n        }\n    }\n}<\/pre>\n<p><!--more--><\/p>\n<p>3\u3001XML<\/p>\n<pre line=\"1\" lang=\"java\"><?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"vertical\"\n    tools:context=\"com.yusian.gamedemo.MainActivity\">\n\n    <EditText\n        android:id=\"@+id\/editText\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"\u6211\u662f\u4e00\u4e2a\u6587\u672c\u8f93\u5165\u6846\"\/>\n\n    <CheckBox\n        android:id=\"@+id\/checkbox1\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"\u659c\u4f53\"\/>\n    <CheckBox\n        android:id=\"@+id\/checkbox2\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"\u7c97\u4f53\"\/>\n<\/LinearLayout><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u4e0a\u56fe 2\u3001Activity package com.yusian.gamedemo; import android.graphics.Typeface; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; public class MainActivity extends AppCompatActivity { private EditText editText; private int style = 0; \/\/ \u5f53\u524d\u7c7b\u578b\uff0c\u5168\u5c40\u7528 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); \/\/ \u6210\u5458\u53d8\u91cf\u8d4b\u503c editText = (EditText)findViewById(R.id.editText); \/\/ \u5c06\u4e24\u4e2aCheckBox\u5206\u522b\u7ed1\u5b9a\u4e8b\u4ef6 CheckBox box1 = (CheckBox)findViewById(R.id.checkbox1); box1.setOnCheckedChangeListener(new CheckBoxListener()); CheckBox box2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[20],"class_list":["post-883","post","type-post","status-publish","format-standard","hentry","category-android","tag-basics"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=883"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/883\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}