《笑话大全》APP代码详解3

本文重点讲解《笑话大全》APP的主页面,作为程序核心,主页面展示了应用的功能。文中通过代码分析了主页面的实现,包括侧滑菜单的逻辑,使用显式Intent进行页面跳转。
摘要由CSDN通过智能技术生成

前面两章讲的启动页和引导页都不是重点,重点在本章所要讲到的主页面,因为主页面才应该是一个程序的核心,程序要展现什么,有什么功能都能够在主页面上体现出来,话不多说,还是先看代码。

public class MainActivity extends AppCompatActivity {
    //主页面的侧滑控件(Google官方控件)
    private DrawerLayout drawerLayout;
    private ScrollView mScrollView;
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        //初始化数据
        initFragment();
        drawerLayout=(DrawerLayout)findViewById(R.id.drawer_layout);
        mScrollView=(ScrollView)findViewById(R.id.drawer_scroll);
    }
    private void initFragment(){

        FragmentManager fm=getSupportFragmentManager();
        //开启FragmentManager的事务
        FragmentTransaction fmTransaction=fm.beginTransaction();
        //利用事务机制替换掉主页面内容的布局文件。不直接在布局文件中写入控件是为了解耦。
        fmTransaction.replace(R.id.content_frameLayout,new ContentFragment());
        //开启事务。
        fmTransaction.commit();
        //禁用DrawerLayout的滑动
    }
    public void stClick(View v){
        if (drawerLayout != null && mScrollView != null){
            drawerLayout.openDrawer(mScrollView);
        }
    }
}
就这么几十行代码,看起来很简单的样子,大体分为这么几个部分:加载主页面布局
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值