将调用 activity 传递给寻呼机适配器

Passing calling activity to pager adapter

正在尝试将调用 activity 发送到寻呼机适配器,以便这两条线路在寻呼机适配器中工作:

((AppCompatActivity) callingActivity).setSupportActionBar(toolbar);

((AppCompatActivity)callingActivity).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

(注意使用寻呼机适配器而不是片段寻呼机适配器)。

您可以使用以下代码执行此操作:

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<TextView
    android:id="@+id/toolbar_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/app_name"
    android:textColor="@color/white"
    android:textSize="@dimen/text_size_medium" />

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

并将此代码放入您的 activity

Typeface typeface = Typeface.createFromAsset(getAssets(), SCTypeface.TTF_REGULAR);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowTitleEnabled(false);
        }

        TextView toolbarTitle = (TextView) findViewById(R.id.toolbar_text);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        toolbarTitle.setText("YOUR TITLE");
        toolbarTitle.setTypeface(typeface);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();

            }
        });