Git Product home page Git Product logo

vntnumberpickerpreference's Introduction

VNTNumberPickerPreference

This is an easy to use custom preference, which opens a dialog with a number picker. The value gets automatically saved and you can set the default-, min- and maxValue conveniently in the XML.

<com.vanniktech.vntnumberpickerpreference.VNTNumberPickerPreference
    xmlns:vntnumberpickerpreference="http://schemas.android.com/apk/res/com.vanniktech.vntnumberpickerpreference"
    android:defaultValue="@integer/font_size_default_value"
    android:key="preference_font_size"
    android:title="@string/font_size"
    vntnumberpickerpreference:maxValue="@integer/font_size_max_value"
    vntnumberpickerpreference:minValue="@integer/font_size_min_value" />

Setup

To get this working in your project, make sure to copy the VNTNumberPickerPreference class.

Afterwards to go your preference XML file and copy the above mentioned XML tag. You may need to modifiy the package description, depending on where you have copied the file.

The declaration of the custom resource id vntnumberpickerpreference happens with xmlns:vntnumberpickerpreference="http://schemas.android.com/apk/res/com.vanniktech.vntnumberpickerpreference". Make sure you replace com.vanniktech.vntnumberpickerpreference with your application package name. You may move the declaration of the custom resource id directly in your PreferenceScreen tag, below the android declaration, to make it accessible globally.

Also you need a file under res/values called attrs.xml with the following content:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="VNTNumberPickerPreference">
        <attr name="minValue" format="integer" />
        <attr name="maxValue" format="integer" />
    </declare-styleable>
</resources>

Afterwards you are good to go and can run your project!

Get font size

final SharedPreferences sharedPreferences = 
    PreferenceManager.getDefaultSharedPreferences(this);
final int fonftSize = sharedPreferences.getInt(
    "preference_font_size", 
    this.getResources().getInteger(R.integer.font_size_default_value));

Preview

Image of VNTNumberPickerPreference

License

Copyright (c) 2014 Niklas Baudy

Licensed under the Apache License, Version 2.0

vntnumberpickerpreference's People

Contributors

vanniktech avatar johnjohndoe avatar

Watchers

James Cloos avatar Luke Chau avatar

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.