özkan özkan - 16 days ago 5
Android Question

The back to home button does not appear. What should I do

The back to home button does not appear.

I added this code and it did not appear again:


getActionBar().setDisplayHomeAsUpEnabled(true);


What should I do in order to show the back button?

My Activity

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


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


My layout


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


My menu

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

Answer

This is where you are missing.. android:theme="@style/AppTheme.NoActionBar"

Change the theme

or

Add custom layout/view inside the ToolBar

Comments