将呼叫活动传递给寻呼机适配器

时间:2018-08-20 17:29:37

标签: android android-pageradapter

尝试将呼叫活动发送到寻呼机适配器,以便这两行在寻呼机适配器中工作:

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

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

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

1 个答案:

答案 0 :(得分:0)

您可以通过使用以下代码来做到这一点:

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

并将此代码放入您的活动

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();

            }
        });