Action bar is shown in the Settings again

This commit is contained in:
serso 2015-01-28 21:43:26 +01:00
parent 3be5a66012
commit 070d0a12d1
4 changed files with 59 additions and 1 deletions

View File

@ -46,7 +46,7 @@
<activity android:clearTaskOnLaunch="true" android:label="@string/c_app_name" android:launchMode="singleTop" android:name=".CalculatorActivityMobile" android:windowSoftInputMode="adjustPan"/>
<!-- settings must use action bar icon-->
<activity android:icon="@drawable/ab_icon" android:label="@string/c_app_settings" android:name=".preferences.PreferencesActivity"/>
<activity android:icon="@drawable/ab_icon" android:label="@string/c_app_settings" android:name=".preferences.PreferencesActivity" android:theme="@style/Theme.Settings"/>
<activity android:label="@string/c_history" android:name=".history.CalculatorHistoryActivity"/>

View File

@ -3,7 +3,11 @@ package org.solovyev.android.calculator.preferences;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import org.solovyev.android.calculator.ActivityUi;
import org.solovyev.android.calculator.AdView;
import org.solovyev.android.calculator.App;
@ -20,15 +24,36 @@ public abstract class BasePreferencesActivity extends PreferenceActivity {
private final ActivityCheckout checkout = Checkout.forActivity(this, App.getBilling(), App.getProducts());
private Inventory inventory;
private AdView adView;
private Toolbar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
actionBar.setTitle(getTitle());
checkout.start();
inventory = checkout.loadInventory();
}
@Override
public void setContentView(int layout) {
final ViewGroup contentView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.cpp_activity_settings, new LinearLayout(this), true);
actionBar = (Toolbar) contentView.findViewById(R.id.action_bar);
actionBar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
final ViewGroup contentWrapper = (ViewGroup) contentView.findViewById(R.id.content_wrapper);
LayoutInflater.from(this).inflate(layout, contentWrapper, true);
getWindow().setContentView(contentView);
}
private class InventoryListener implements Inventory.Listener {
@Override

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize" />
<FrameLayout
android:id="@+id/content_wrapper"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>

View File

@ -28,4 +28,18 @@
<style name="Theme.Base" parent="@style/Theme.AppCompat"></style>
<style name="Theme.Base.Dialog" parent="@style/Theme.AppCompat.Dialog"></style>
<style name="Theme.Settings" parent="@style/cpp_metro_blue_theme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="toolbarStyle">@style/Widget.Toolbar</item>
</style>
<style name="Widget.Toolbar" parent="@style/Widget.AppCompat.Toolbar">
<item name="android:background">?attr/colorPrimary</item>
<item name="android:navigationIcon">?attr/homeAsUpIndicator</item>
<item name="navigationIcon">?attr/homeAsUpIndicator</item>
</style>
</resources>