Fragment侧滑

XML:

<android.support.v4.widget.DrawerLayout
    android:id="@+id/draw"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <fragment
        android:id="@+id/fragment"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        class="guopuran.bwie.com.cehua.Fragmentone"
        android:layout_gravity="start"
        />


</android.support.v4.widget.DrawerLayout>

fragmentonexml:

<TextView
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:text="11111"/>

values文件夹中strings.xml:

<resources>
    <string name="app_name">cehua</string>
    <string name="kai">kai</string>
    <string name="guan">guan</string>
</resources>

Fragment类:

    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragmentone,container,false);
        return view;

    }

Activity:

    private DrawerLayout drawerLayout;
    private ActionBar actionBar;
    private ActionBarDrawerToggle toggle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //获取资源ID
        drawerLayout = findViewById(R.id.draw);
        actionBar = getSupportActionBar();
        //顶部的开启按钮
        actionBar.setDisplayHomeAsUpEnabled(true);
        toggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.kai, R.string.guan);
        //同步
        toggle.syncState();
        drawerLayout.addDrawerListener(toggle);

    }
    //点击事件
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (toggle.onOptionsItemSelected(item)){
            return  true;
        }
        return super.onOptionsItemSelected(item);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值