zoukankan      html  css  js  c++  java
  • Android快速开发(2)

    1.底部导航栏实现

    MyFragment.java
    public class MyFragment extends Fragment {
    
        private String content;
        private TextView txt_title;
        private FrameLayout myfragment_contet;
        private Context mContext;
        private ArrayList<Data> datas = null;
        private FragmentManager fManager = null;
        private long exitTime = 0;
    
        public MyFragment(String content) {
            this.content = content;
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            if (content == "first1") {
                View view = inflater.inflate(R.layout.myfg_message, container, false);
                WebView main_webcontent = (WebView) view.findViewById(R.id.webView1);
                String url = "http://www.baidu.com";
                main_webcontent.loadUrl(url);
                return view;
            } else {
                View view = inflater.inflate(R.layout.myfragment_content, container, false);
                TextView txt_content = (TextView) view.findViewById(R.id.txt_content);
                txt_content.setText(content);
                return view;
            }
        }
    
    }
    
    MainActivity.java
    public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener{
        private RadioGroup rg_tab_bar;
        private RadioButton rb_channel;
        //Fragment Object
        private MyFragment fg1,fg2,fg3,fg4;
        private FragmentManager fManger;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            fManger =getFragmentManager();
            rg_tab_bar = (RadioGroup) findViewById(R.id.rg_tab_bar);
            rg_tab_bar.setOnCheckedChangeListener(this);
            //获取第一个单选按钮,并设置其为选中状态
            rb_channel = (RadioButton) findViewById(R.id.rb_channel);
            rb_channel.setChecked(true);
        }
    
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            FragmentTransaction fTransaction = fManger.beginTransaction();
            hideAllFragment(fTransaction);
            switch (checkedId){
                case R.id.rb_channel:
                    if(fg1 == null){
                        fg1=new MyFragment("first1");
                        fTransaction.add(R.id.ly_content,fg1);
                    }
                    else {
                        fTransaction.show(fg1);
                    }
                    break;
                case R.id.rb_message:
                    if(fg2 == null){
                        fg2 = new MyFragment("第二个Fragment");
                        fTransaction.add(R.id.ly_content,fg2);
                    }else{
                        fTransaction.show(fg2);
                    }
                    break;
                case R.id.rb_better:
                    if(fg3 == null){
                        fg3 = new MyFragment("第三个Fragment");
                        fTransaction.add(R.id.ly_content,fg3);
                    }else{
                        fTransaction.show(fg3);
                    }
                    break;
                case R.id.rb_setting:
                    if(fg4 == null){
                        fg4 = new MyFragment("第四个Fragment");
                        fTransaction.add(R.id.ly_content,fg4);
                    }else{
                        fTransaction.show(fg4);
                    }
                    break;
            }
            fTransaction.commit();
        }
        //隐藏所有Fragment
        private void hideAllFragment(FragmentTransaction fragmentTransaction){
            if(fg1!=null)fragmentTransaction.hide(fg1);
            if(fg2 != null)fragmentTransaction.hide(fg2);
            if(fg3 != null)fragmentTransaction.hide(fg3);
            if(fg4 != null)fragmentTransaction.hide(fg4);
        }
    }
    

    2.自动添加生命周期控件
    这里写图片描述这里写图片描述
    You are correct: that code is automatically created for you by Android Studio, to aid in the implementation of the App Indexing API.

    However, it is not created by simply adding a new activity to your app. You would need to explicitly ask Android Studio to create this code. You would then need to update it with details of your activity: Type of Action, Title, Deep Link, Corresponding Web Page (if one exists).

    To have this code generated for you, you can use the pop-up intention list by Alt + Enter, select “Insert App Indexing API Code”:

    enter image description here

    Or you can use pop-up code generate list by Alt + Insert, select “App Indexing API Code”:

    enter image description here

  • 相关阅读:
    「Vijos 1282」「OIBH杯NOIP2006第二次模拟赛」佳佳的魔法照片
    「Vijos 1285」「OIBH杯NOIP2006第二次模拟赛」佳佳的魔法药水
    「Vijos 1284」「OIBH杯NOIP2006第二次模拟赛」佳佳的魔法阵
    「Vijos 1283」「OIBH杯NOIP2006第二次模拟赛」佳佳的魔杖
    「2018-12-02模拟赛」T3 约束排列 解题报告
    「2018-12-02模拟赛」T2 种树 解题报告
    「2018-12-02模拟赛」T1 最短路 解题报告
    「分块系列」公主的朋友 解题报告
    「分块系列」「洛谷P4168 [Violet]」蒲公英 解题报告
    Java高级架构师(一)第03节:多模块多Web应用合并War包
  • 原文地址:https://www.cnblogs.com/zychen/p/7384763.html
Copyright © 2011-2022 走看看