簡體   English   中英

工具欄(不顯示“后退”按鈕)

[英]Toolbar(Back button not Showing)

我復制了Universal Image Loader的代碼並進行了一些調整。
但是當我放工具欄時,沒有顯示向后導航。
這是代碼。
我還可以使用UIL進行圖像的多重選擇嗎?
謝謝。

package com.thesis.juandirection.juandirectionfinale;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import com.thesis.juandirection.juandirectionfinale.fragments.ImageGridFragment;
import com.thesis.juandirection.juandirectionfinale.fragments.ImageListFragment;
import com.thesis.juandirection.juandirectionfinale.fragments.ImageGalleryFragment;
import com.thesis.juandirection.juandirectionfinale.fragments.ImagePagerFragment;
import com.thesis.juandirection.juandirectionfinale.review.reviewView;

public class SimpleImageActivity extends AppCompatActivity{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fr_image_grid);
        Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Review: Bulacan State University");
        int frIndex = getIntent().getIntExtra(Constants.Extra.FRAGMENT_INDEX, 0);
        Fragment fr;
        String tag;
        int titleRes;
        switch (frIndex) {
            default:
            case ImageListFragment.INDEX:
                tag = ImageListFragment.class.getSimpleName();
                fr = getSupportFragmentManager().findFragmentByTag(tag);
                if (fr == null) {
                    fr = new ImageListFragment();
                }
                titleRes = R.string.ac_name_image_list;
                break;
            case ImageGridFragment.INDEX:
                tag = ImageGridFragment.class.getSimpleName();
                fr = getSupportFragmentManager().findFragmentByTag(tag);
                if (fr == null) {
                    fr = new ImageGridFragment();
                }
                titleRes = R.string.ac_name_image_grid;
                break;
            case ImagePagerFragment.INDEX:
                tag = ImagePagerFragment.class.getSimpleName();
                fr = getSupportFragmentManager().findFragmentByTag(tag);
                if (fr == null) {
                    fr = new ImagePagerFragment();
                    fr.setArguments(getIntent().getExtras());
                }
                titleRes = R.string.ac_name_image_pager;
                break;
            case ImageGalleryFragment.INDEX:
                tag = ImageGalleryFragment.class.getSimpleName();
                fr = getSupportFragmentManager().findFragmentByTag(tag);
                if (fr == null) {
                    fr = new ImageGalleryFragment();
                }
                titleRes = R.string.ac_name_image_gallery;
                break;
        }

        setTitle(titleRes);

        getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fr, tag).commit();

    }

    /*public void goBack(View view){
        startActivity(new Intent(getApplicationContext(), reviewView.class));
    }*/
}

XML ..

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white"
            tools:context="com.example.directioner.newjd.MainActivity">

            <include
                android:id="@+id/app_bar"
                layout="@layout/app_bar" />
            <GridView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/grid"
                android:layout_below="@+id/app_bar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:horizontalSpacing="4dip"
                android:numColumns="3"
                android:padding="4dip"
                android:stretchMode="columnWidth"
                android:verticalSpacing="4dip" />


        </RelativeLayout>
    </FrameLayout>
</RelativeLayout>

我的AndroidManifest。

<activity
            android:name=".SimpleImageActivity"
            android:label="@string/title_activity_simple_image"
            android:theme="@style/AppTheme" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".review.reviewView" />
        </activity>  

我錯過了什么? 提前致謝,

您缺少getSupportActionBar()。setHomeButtonEnabled(true) 有關更多信息,請通過工具欄的子元素頂部的添加”后退按鈕

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM