片段中的Android工具栏

时间:2016-02-24 08:03:17

标签: android android-fragments toolbar

我有一个活动,显示两个按钮登录和注册,没有工具栏 我想在fragments中直接显示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); 我该怎么做?

<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"
            >

这是它的Xml

line.replace(src, dst)

1 个答案:

答案 0 :(得分:1)

     <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>