Skip to content

Commit

Permalink
Add Toolbar on Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersantos committed Jun 13, 2015
1 parent 6de9036 commit 4d9899c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ private void setInitialConfiguration() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.action_about);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.javiersantos.mlmanager.R;
import com.javiersantos.mlmanager.utils.AppPreferences;
Expand All @@ -20,7 +25,8 @@

public class SettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
// Load Settings
AppPreferences appPreferences;
private AppPreferences appPreferences;
private Toolbar toolbar;

// Settings variables
private SharedPreferences prefs;
Expand All @@ -34,7 +40,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.activity_settings);
addPreferencesFromResource(R.xml.settings);
this.context = this;
this.appPreferences = new AppPreferences(getApplicationContext());

Expand Down Expand Up @@ -100,11 +106,33 @@ public boolean onPreferenceClick(Preference preference) {

}

@Override
public void setContentView(int layoutResID) {
ViewGroup contentView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.activity_settings, new LinearLayout(this), false);
toolbar = (Toolbar) contentView.findViewById(R.id.toolbar);
//TODO Toolbar should load the default style in XML (white title and back arrow), but doesn't happen
toolbar.setTitleTextColor(getResources().getColor(R.color.white));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});

ViewGroup contentWrapper = (ViewGroup) contentView.findViewById(R.id.content_wrapper);
LayoutInflater.from(this).inflate(layoutResID, contentWrapper, true);
getWindow().setContentView(contentView);

}

private void setInitialConfiguration() {
toolbar.setTitle(getResources().getString(R.string.action_settings));

// Android 5.0+ devices
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(UtilsUI.darker(appPreferences.getPrimaryColorPref(), 0.8));
toolbar.setBackgroundColor(appPreferences.getPrimaryColorPref());
if (!appPreferences.getNavigationBlackPref()) {
getWindow().setNavigationBarColor(appPreferences.getPrimaryColorPref());
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<FrameLayout
android:id="@+id/content_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
7 changes: 4 additions & 3 deletions app/src/main/res/layout/toolbar.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:navigationIcon="?attr/homeAsUpIndicator"/>
File renamed without changes.

0 comments on commit 4d9899c

Please sign in to comment.