Coder Social home page Coder Social logo

materialsettings's Introduction

Deprecated (No Longer Developed)

This example is no longer maintained as Google have implemented the AppCompatDelegate class to implement Material Design in a PreferenceActivity.


Banner

MaterialSettings

The open repository with a global support for Android 5 Toolbar within any Settings Activity (PreferenceActivity), compatible with API 10 and above.

IMPORTANT - Compatibility

Element Tinting

In order to mimic (material-like) element tinting on pre-L devices utilise the following code:

@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
    // Allow super to try and create a view first
    final View result = super.onCreateView(name, context, attrs);
    if (result != null) {
        return result;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // If we're running pre-L, we need to 'inject' our tint aware Views in place of the
        // standard framework versions
        switch (name) {
            case "EditText":
                return new AppCompatEditText(this, attrs);
            case "Spinner":
                return new AppCompatSpinner(this, attrs);
            case "CheckBox":
                return new AppCompatCheckBox(this, attrs);
            case "RadioButton":
                return new AppCompatRadioButton(this, attrs);
            case "CheckedTextView":
                return new AppCompatCheckedTextView(this, attrs);
        }
    }

    return null;
}

Remember: Import the appcompt-v7 library in your app.gradle:
compile 'com.android.support:appcompat-v7:22.2.0'

Gingerbread

In order to handle nested PreferenceScreens correctly onConfigurationChanged() must be overriden in your SettingsActivity as below:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

and so this code is called, add the following to your SettingsActivity declaration in your AndroidManifest.xml:

android:configChanges="keyboard|keyboardHidden|orientation|screenSize"

Full Example:

<activity
    android:name=".SettingsExampleActivity"
    android:label="@string/title_activity_settings_example"
    android:theme="@style/AppTheme.NoActionBar"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Thanks to @hclemens for indentifying this.

Toolbar Shadow

To simulate the elevation of the Toolbar on pre-L devices, utilise the following code:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

   <android.support.v7.widget.Toolbar
       .../>

</android.support.design.widget.AppBarLayout>

Remember: Import the Design library in your app.gradle:
compile 'com.android.support:design:22.2.0'

materialsettings's People

Contributors

1priyank1 avatar davcpas1234 avatar kosratdev avatar robertschulze avatar vc-whitchurcha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

materialsettings's Issues

ClassCastException error on Lollipop devices

The method below:

@Override
protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            // This line failed on Lollipop devices.
            LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
       }
}

caused a ClassCastException on Lollipop devices:

java.lang.ClassCastException: com.android.internal.widget.ActionBarOverlayLayout cannot be cast to android.widget.LinearLayout

Is there a workaround for this issue for Lollipop devices?

Here's my dec;laration for the Toolbar:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:navigationIcon="?attr/homeAsUpIndicator"/>

ClassCastException in nested preference screens Android API 24

In Android API 24, in NESTED PREFERENCE SCREENS, in this line ( LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent(); ) I'm getting this error: java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to android.widget.LinearLayout.

Is any solution for this???

android.os.BadParcelableException

Hi,
my firebase crash reporting reports me this error (Caused by android.os.BadParcelableException: ClassNotFoundException when unmarshalling: android.support.v7.widget.Toolbar$SavedState) on using MaterialSettings
I'm googling it but not found any useful answer.

license?

Hi what would be the license for your code?

Android N - Root View Cast Error

@davcpas1234
LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();

this code is error in Android N, findViewById(android.R.id.list).getParent().getParent().getParent() is FrameLayout.

Normal Color Control

you are set normal color control to white which is not visible if the control in inactive mode look at the picture:

device-2016-11-23-190749

ClassCastException with LG Devices

Hi,

My firebase crash reporting reports this error:
Exception java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to android.widget.LinearLayout com.kosratdahmad.myprayers.activities.SettingsActivity.setUpNestedScreen (SettingsActivity.java) com.kosratdahmad.myprayers.activities.SettingsActivity.onPreferenceTreeClick (SettingsActivity.java) android.preference.Preference.performClick (Preference.java:1005) android.preference.PreferenceScreen.onItemClick (PreferenceScreen.java:214) android.widget.AdapterView.performItemClick (AdapterView.java:310) android.widget.AbsListView.performItemClick (AbsListView.java:1199) android.widget.AbsListView$PerformClick.run (AbsListView.java:3171) android.widget.AbsListView$3.run (AbsListView.java:4225) android.os.Handler.handleCallback (Handler.java:751) android.os.Handler.dispatchMessage (Handler.java:95) android.os.Looper.loop (Looper.java:154) android.app.ActivityThread.main (ActivityThread.java:6247) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:872) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:762)

This code makes this error only in LG G5 and LG V20 on api level 24:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent(); appBar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_settings, root, false); root.addView(appBar, 0); }

I tested on Nexus 5X api level 24 and 25 it works fine and I don't know why makes this error on LG devices

NPE On Sony Ericsson Running 4.0.4

LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();

Worked when changed to:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)

Toolbar disappearing

Hi,

I'm not sure I'm right here, but I came here from your awesome SO answer.
I used the code, you have listed below the Gingerbread-fix, but discovered a problem:
When my nested preference screen (dialog) is opened and I lock my screen, and unlock it some seconds later, the toolbar is gone, and there's only the content of the nested pref.Screen visible.

I hope you encountered this before and know how to fix it.
Thanks in advance!

Shows Nothing

Settings shows nothing in Api Level 25

look at my screen shot:

device-2017-01-23-001059

ClassCastException on API level 15

Hi,

My firebase crash reporting reports this error (java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.ListView) on api level 15.

Sony Ericsson Running 4.0.4 - Nested Screen Back Button not working

This is due to padding overlapping back arrow (hence it's not clickable). In my case following code for nested screens worked better (using vertical linear layout)

public void setUpNestedScreen(PreferenceScreen preferenceScreen) {
        final Dialog dialog = preferenceScreen.getDialog();

        Toolbar bar;

        View listRoot = dialog.findViewById(android.R.id.list);
        ViewGroup mRootView = (ViewGroup) dialog.findViewById(android.R.id.content);


        if (listRoot != null) {
            LinearLayout root = (LinearLayout) listRoot.getParent();
            bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar, root, false);
            root.addView(bar, 0); // insert at top
        } else {
            ListView content = (ListView) mRootView.getChildAt(0);
            mRootView.removeAllViews();

            LinearLayout LL = new LinearLayout(this);
            LL.setOrientation(LinearLayout.VERTICAL);

            ViewGroup.LayoutParams LLParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            LL.setLayoutParams(LLParams);

            bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar, mRootView, false);

            LL.addView(bar);
            LL.addView(content);

            mRootView.addView(LL);
        }

        if(listRoot != null)
            listRoot.setPadding(0, listRoot.getPaddingTop(), 0, listRoot.getPaddingBottom());

        bar.setTitle(preferenceScreen.getTitle());

        bar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }

Back Button not working when using AppBar

When using AppBarLayout for the shadow effect instead of straightforward Toolbar bar.setNavigationOnClickListener in the sample code is not available, because I had to cast it on AppBarLayout

BindPreferenceSummaryToValue Issue

The function bindPreferenceSummaryToValue is called only once.
For Example,
I have two EditTextPreference which needs to set their summary to corresponding values.
Only the first EditText gets summary updated. Not the second one.
There is no problem in saving and reading the values.
It just the UI which is not nice.

Please fix asap

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.