added back button to action bar.

This commit is contained in:
Kevin Meyer 2014-08-20 10:54:27 +02:00
parent 7fcd254b80
commit 5a80076e8a
3 changed files with 58 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
@ -24,6 +25,15 @@ public class ListArticles extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
try {
getActionBar().setDisplayHomeAsUpEnabled(true);
} catch (Exception e) {
//
}
}
setupDB();
setupList(false);
}
@ -55,7 +65,10 @@ public class ListArticles extends Activity {
ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(this);
helper.truncateTables(database);
setupList(false);
super.onOptionsItemSelected(item);
return super.onOptionsItemSelected(item);
case android.R.id.home:
this.finish();
return super.onOptionsItemSelected(item);
default:
return super.onOptionsItemSelected(item);
}

View File

@ -14,7 +14,9 @@ import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
@ -43,6 +45,15 @@ public class ReadArticle extends Activity {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.article);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
try {
getActionBar().setDisplayHomeAsUpEnabled(true);
} catch (Exception e) {
//
}
}
view = (ScrollView) findViewById(R.id.scroll);
ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(getApplicationContext());
database = helper.getWritableDatabase();
@ -137,5 +148,15 @@ public class ReadArticle extends Activity {
super.onDestroy();
database.close();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return super.onOptionsItemSelected(item);
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@ -4,7 +4,9 @@ import static fr.gaulupeau.apps.Poche.Helpers.PREFS_NAME;
import fr.gaulupeau.apps.InThePoche.R;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@ -23,6 +25,15 @@ public class Settings extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
try {
getActionBar().setDisplayHomeAsUpEnabled(true);
} catch (Exception e) {
//
}
}
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String pocheUrl = settings.getString("pocheUrl", "http://");
String apiUsername = settings.getString("APIUsername", "");
@ -52,4 +63,15 @@ public class Settings extends Activity {
//
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}