不显示返回主页按钮。我该怎么办

时间:2016-11-15 13:30:28

标签: java android android-actionbar

不会出现返回主页按钮。

我添加了此代码,但它没有再出现:

  

getActionBar()setDisplayHomeAsUpEnabled(真);

我应该怎么做以显示后退按钮?

我的活动

package com.kamu.kamu_bilgi;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class ekran18 extends AppCompatActivity {


    private WebView mWebView;

    private Menu optionsMenu;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {//Menüyü oluşturuyoruz
        this.optionsMenu = menu;

        MenuInflater inflater = getMenuInflater();// inflater herhangi bir view ın java objesine dönüştürülüp düzenlenmesinde yardımcı olur.Burda menü düzenlenmesi için kullanacağız
        inflater.inflate(R.menu.main_activity_actions, menu);//Xml olarak oluşturduğumuz menü yü alıyoruz

        return super.onCreateOptionsMenu(menu);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {// Action Bar itemden herhangi biri tıklandığında

        switch (item.getItemId()) {

            case R.id.action_settings: //settings iconu tıklandığında

                settings();

                break;


            case R.id.action_paylas: //share iconu

                share();

                break;


            case R.id.action_yenile://refresh iconu

                refresh();

                return true;

            case android.R.id.home:
                // app icon in action bar clicked; goto parent activity.
                this.finish();
                return true;


            default:
                return super.onOptionsItemSelected(item);
        }
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sayfa18);


        mWebView = (WebView) findViewById(R.id.webView);

        assert mWebView != null;
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.loadUrl("http://www.kamu.com/kamupersoneli/ilanlar/");
        mWebView.setWebViewClient(new HelloWebViewClient());

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar2);
        setSupportActionBar(toolbar);


    }

    private class HelloWebViewClient extends WebViewClient{


        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, String url)
        {
            webView.loadUrl(url);
            return true;
        }
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    { //if back key is pressed
        if((keyCode == KeyEvent.KEYCODE_BACK)&& mWebView.canGoBack())
        {
            mWebView.goBack();
            return true;

        }

        return super.onKeyDown(keyCode, event);

    }

    public void share(){
        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        String shareMesaj = "";
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
        sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
        startActivity(Intent.createChooser(sharingIntent, ""));

    }
    public void settings(){
        Intent myIntent = new Intent(getApplicationContext(), Ayarlar.class);
        startActivity(myIntent);

    }
    public void refresh(){

        setRefreshActionButtonState(true);//progress bar refresh iconla değişecek ve çalışacak .
        mWebView.reload();
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                setRefreshActionButtonState(false);//3 sn sonra duracak ve refresh iconu geri gelecek. Siz bu arada başka işlemler sunucu bağlantısı vs.. yapabilirsiniz

            }
        }, 3000);
    }
    public void setRefreshActionButtonState(final boolean refreshing) {

        //bu method refresh iteme tıklandığında progress bar gözükmesi için
        if (optionsMenu != null) {
            final MenuItem refreshItem = optionsMenu
                    .findItem(R.id.action_yenile);
            if (refreshItem != null) {
                if (refreshing) {
                    refreshItem.setActionView(R.layout.actionbar_refresh_progress);
                } else {
                    refreshItem.setActionView(null);
                }
            }
        }
    }
}

我的AndroidManifest

<activity android:name=".ekran18"
            android:label="@string/title_activity_sayfa18"
            android:screenOrientation="fullSensor"
            android:launchMode="singleTop"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:parentActivityName="com.kamubilgi.kamu_bilgi.MainActivity"
            android:theme="@style/AppTheme.NoActionBar">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.kamubilgi.kamu_bilgi.MainActivity" /></activity>

我的布局

<FrameLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context="com.kamubilgi.kamu_bilgi.ekran18">

    <!-- TODO: Update blank fragment layout -->

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:ignore="UselessParent">

        <WebView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/webView" >

        </WebView>

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/holo_red_dark"
            android:theme="?attr/actionBarTheme"
            android:minHeight="?attr/actionBarSize"
            android:id="@+id/toolbar2" />

    </RelativeLayout>

</FrameLayout>

我的菜单

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <!-- Arama, eylem düğmesi olarak görülebilir -->

    <item android:id="@+id/action_geri"
        android:icon="@drawable/ic_keyboard_arrow_left_white_24px"
        android:title="@string/action_arama"
        app:showAsAction="always"
       />
    <item android:id="@+id/action_paylas"
        android:icon="@drawable/ic_share_white_24px"
        android:title="@string/action_arama"
        app:showAsAction="always"
        />

    <item android:id="@+id/action_yenile"
        android:icon="@drawable/ic_autorenew_white_24px"
        android:title="@string/action_arama"
        app:showAsAction="always" />


    <!-- Ayarlar, daima taşan eylemler bölümünde durabilir -->
    <item android:id="@+id/action_ayarlar"
        android:title="@string/action_settings"
        app:showAsAction="never" />
</menu>

1 个答案:

答案 0 :(得分:0)

这是你失踪的地方.. 机器人:主题= “@风格/ AppTheme.NoActionBar”

更改主题

在工具栏中添加自定义布局/视图