【问题标题】:Implementing sliding tab within fragment在片段中实现滑动选项卡
【发布时间】:2017-01-19 07:20:45
【问题描述】:

我有一个导航抽屉,抽屉内的每个项目都有一个片段页面。我想在一个片段中实现选项卡式滑动。我怎么做。 这是我点击一个导航抽屉片段页面后的代码。我想在此页面中实现选项卡式视图。有什么办法?

//代码

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;


/**
 * A simple {@link Fragment} subclass.
 */
public class SalesFragment extends Fragment {
    private Toolbar mToolbar;





    public SalesFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        setHasOptionsMenu(true);
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_sales, container, false);
    }
    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.toolbar_menu, menu);
        super.onCreateOptionsMenu(menu, inflater);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.add_user) {
            return true;
        }

        if (id == R.id.barcode_scanner) {
            return true;
        }
        if (id == R.id.search_overflow) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


}

//这里是布局xml页面

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.soumya.possystem.SalesFragment">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Sales page"
        android:textSize="40dp"/>

</FrameLayout>

【问题讨论】:

    标签: android android-fragments navigation-drawer android-tabbed-activity


    【解决方案1】:

    您可以使用Android Studio Activity Gallery 创建选项卡式片段页面查看器。只需按照以下步骤,半分钟即可完成。

    ->文件->新建->活动->选择类型Tabbed Activity

    -> 选择导航样式操作栏选项卡(使用 ViewPager)

    享受编码!

    【讨论】:

    • 不不!!请阅读我的问题。我想在已经创建的片段页面中实现它。请看我的代码。
    • 你指的是一个活动,但我需要在一个片段中实现它。
    猜你喜欢
    • 2016-08-13
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 2015-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多