Kaustubh Bhagwat
Kaustubh Bhagwat

Reputation: 2833

Android toolbar in fragment

I have a activity which shows two buttons sign in and signup and has no toolbar I am trying to show the toolbar directly in the fragments how can I do this ?

public class SignUpFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {

    private AutoCompleteTextView mEmailView, mPhoneNoView;
    private EditText mFirstNameView, mLastNameView, mPasswordView, mConfirmPasswordView;
    private LoginActivity mActivity;
        private Toolbar toolbar;
    /*    private SignInActivity mSignInActivity;
    private SignInButton mPlusSignInButton;*/
    private Button mFBSignInButton,mPlusSignInButton;

    private UserRegisterTask mUserRegisterTask;

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

    public static SignUpFragment newInstance() {
        SignUpFragment fragment = new SignUpFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_sign_up, container, false);
        mFirstNameView = (EditText) rootView.findViewById(R.id.fragment_signup_et_firstname);
        mLastNameView = (EditText) rootView.findViewById(R.id.fragment_signup_et_lastname);


        Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar_signup);
        Toolbar toolbar1 = ((Toolbar)getActivity()).getSupportActionBar();
        toolbar1.setTitle("First Fragment");
        toolbar1.setDisplayHomeAsUpEnabled(true);
        toolbar1.setHomeButtonEnabled(true);

This is its Xml

<android.support.v4.widget.NestedScrollView android:id="@+id/activity_event_details_scrollview"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    xmlns:app="http://schemas.android.com/apk/res-auto">




    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_signup"
            app:title="Register"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        </android.support.v7.widget.Toolbar>



        <View
            android:layout_width="wrap_content"
            android:layout_height="3dp"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:background="@color/grey200"/>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="16dp"
            >

Upvotes: 0

Views: 671

Answers (1)

Akshay Shinde
Akshay Shinde

Reputation: 947

     <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

    <TextView
        android:id="@+id/toolbar_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:drawableLeft="@drawable/ic_backnarrow_white"
        android:drawablePadding="14dp"
        android:gravity="center"
        android:text="REGISTER"
        android:textColor="@color/background_light"
        android:textSize="16dp"
        app:textStyle="@integer/RALEWAY_MEDIUM"/>

</android.support.v7.widget.Toolbar>

Upvotes: 1

Related Questions