简体   繁体   中英

Toolbar(Back button not Showing)

I copied the codes of Universal Image Loader and made some tweaks.
But when I put my toolbar,the back navigation is not showing.
Here's the code.
And Also can I use UIL for multi selection of image?.
Thanks.

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>

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

What did I miss? Thanks in advance,

You are missing getSupportActionBar().setHomeButtonEnabled(true) . for more information please go through the Adding backbutton on top of child element of Toolbar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM