{"id":306,"date":"2022-09-30T21:25:16","date_gmt":"2022-09-30T13:25:16","guid":{"rendered":"http:\/\/blog.nhl520.cn\/?p=306"},"modified":"2022-11-11T19:32:38","modified_gmt":"2022-11-11T11:32:38","slug":"android-fragment%e4%ba%8b%e4%bb%b6%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.nhl520.cn\/index.php\/2022\/09\/30\/android-fragment%e4%ba%8b%e4%bb%b6%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95\/","title":{"rendered":"Android Fragment\u4e8b\u4ef6\u4f7f\u7528\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u4f7f\u7528\u8bf4\u660e\uff1a\u8fd9\u9700\u8981\u81ea\u5df1\u5355\u72ec\u521b\u5efafragment\u9875\u9762\u7684<\/p>\n\n\n\n<p>1\u3001XML\u6587\u4ef6\u6dfb\u52a0\u4ee5\u4e0b<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> &lt;LinearLayout\n        android:layout_weight=\"1\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\">\n        &lt;RelativeLayout\n            android:layout_weight=\"1\"\n            android:id=\"@+id\/main_fragment1\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\">\n\n        &lt;\/RelativeLayout>\n    &lt;\/LinearLayout>\n\n    &lt;LinearLayout\n        android:layout_weight=\"8.5\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\">\n\n        &lt;androidx.cardview.widget.CardView\n            app:cardBackgroundColor=\"@color\/white\"\n            android:layout_margin=\"10dp\"\n            app:cardCornerRadius=\"999dp\"\n            app:cardMaxElevation=\"0dp\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\">\n            &lt;LinearLayout\n                android:orientation=\"horizontal\"\n                android:layout_width=\"match_parent\"\n                android:layout_height=\"match_parent\">\n                &lt;LinearLayout\n                    android:id=\"@+id\/shouye\"\n                    android:gravity=\"center\"\n                    android:layout_weight=\"1\"\n                    android:orientation=\"vertical\"\n                    android:layout_width=\"match_parent\"\n                    android:layout_height=\"match_parent\">\n                    &lt;ImageView\n                        android:id=\"@+id\/shouyeimg\"\n                        android:src=\"@mipmap\/home\"\n                        android:layout_width=\"30dp\"\n                        android:layout_height=\"30dp\">\n\n                    &lt;\/ImageView>\n                    &lt;TextView\n                        android:id=\"@+id\/sycolor\"\n                        android:text=\"\u9996\u9875\"\n                        android:textSize=\"13sp\"\n                        android:textColor=\"#1296db\"\n                        android:layout_width=\"wrap_content\"\n                        android:layout_height=\"wrap_content\">\n\n                    &lt;\/TextView>\n                &lt;\/LinearLayout>\n                &lt;LinearLayout\n                    android:id=\"@+id\/wd\"\n                    android:orientation=\"vertical\"\n                    android:gravity=\"center\"\n                    android:layout_weight=\"1\"\n                    android:layout_width=\"match_parent\"\n                    android:layout_height=\"match_parent\">\n                    &lt;ImageView\n                        android:id=\"@+id\/wdimg\"\n                        android:src=\"@mipmap\/wd_1\"\n                        android:layout_width=\"30dp\"\n                        android:layout_height=\"30dp\">\n\n                    &lt;\/ImageView>\n                    &lt;TextView\n                        android:id=\"@+id\/wdcolor\"\n                        android:text=\"\u6211\u7684\"\n                        android:textSize=\"13sp\"\n                        android:textColor=\"#E5E5E5\"\n                        android:layout_width=\"wrap_content\"\n                        android:layout_height=\"wrap_content\">\n\n                    &lt;\/TextView>\n\n                &lt;\/LinearLayout>\n\n            &lt;\/LinearLayout>\n\n      &lt;\/androidx.cardview.widget.CardView>\n    &lt;\/LinearLayout><\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> \/\/\u5e95\u90e8\u5355\u51fbid\u8bbe\u7f6e\n        LinearLayout linearLayout = findViewById(R.id.shouye);\/\/\u9996\u9875\n        LinearLayout linearLayout2 = findViewById(R.id.wd);\n\n        \/\/\u5e95\u90e8\u83dc\u5355\u56fe\u7247\u8bbe\u7f6e\n        ImageView imageView = findViewById(R.id.shouyeimg);\/\/\u9996\u9875\n        ImageView imageView2 = findViewById(R.id.wdimg);\/\/\u6211\u7684\n\n        \/\/\u5e95\u90e8\u83dc\u5355\n        \/\/ \u6587\u5b57\u989c\u8272\u8bbe\u7f6e\n        TextView textView=findViewById(R.id.sycolor);\n        TextView textView2=findViewById(R.id.wdcolor);\n\n\n        \/\/\u5e95\u90e8\u5bfc\u822afragment\u90e8\u5206\n        FragmentManager manager = getSupportFragmentManager();\n        \/\/\u5c06\u9996\u9875\u6dfb\u52a0\u8fdb\u53bb\n        FragmentTransaction transaction = manager.beginTransaction();\n        transaction.replace(R.id.main_fragment1, new shouyeFragment());\/\/home\u91cc\u7684id\n        transaction.commit();\n        \/\/\u5c06\u9996\u9875\u6dfb\u52a0\u8fdb\u53bb\u7ed3\u675f\n\n        \/\/\u9996\u9875\u5355\u51fb\u4e8b\u4ef6\n        linearLayout.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View view) {\n                imageView2.setImageResource(R.mipmap.wd_1);\/\/\u56fe\u7247\u66f4\u6539\n                imageView.setImageResource(R.mipmap.home);\/\/\u56fe\u7247\u66f4\u6539\n                textView.setTextColor(Color.parseColor(\"#1296db\"));\n                textView2.setTextColor(Color.parseColor(\"#E5E5E5\"));\n                FragmentTransaction transaction = manager.beginTransaction();\n                transaction.replace(R.id.main_fragment1, new shouyeFragment());\/\/home\u91cc\u7684id\n                transaction.commit();\n            }\n        });\n        \/\/\u6211\u7684\u5355\u51fb\u4e8b\u4ef6\n        linearLayout2.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View view) {\n                imageView.setImageResource(R.mipmap.home_1);\/\/\u56fe\u7247\u66f4\u6539\n                imageView2.setImageResource(R.mipmap.wd);\/\/\u56fe\u7247\u66f4\u6539\n                textView2.setTextColor(Color.parseColor(\"#1296db\"));\n                textView.setTextColor(Color.parseColor(\"#E5E5E5\"));\n                FragmentTransaction transaction = manager.beginTransaction();\n                transaction.replace(R.id.main_fragment1, new wdFragment());\/\/home\u91cc\u7684id\n                transaction.commit();\n            }\n        });<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u8bf4\u660e\uff1a\u8fd9\u9700\u8981\u81ea\u5df1\u5355\u72ec\u521b\u5efafragment\u9875\u9762\u7684 1\u3001XML\u6587\u4ef6\u6dfb\u52a0\u4ee5\u4e0b<\/p>\n","protected":false},"author":1,"featured_media":172,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-306","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android"],"_links":{"self":[{"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/posts\/306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/comments?post=306"}],"version-history":[{"count":5,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/posts\/306\/revisions"}],"predecessor-version":[{"id":311,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/posts\/306\/revisions\/311"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/media\/172"}],"wp:attachment":[{"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/media?parent=306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/categories?post=306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/tags?post=306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}