Tag: morsels

Monthly Android Morsels [December 2015]

Monthly Android Morsels [December 2015]

Tips and Tricks for December 2015:

  1. Hyphenation in Android TextView – In API 23, Google introduced hyphenation for TextViews. Hyphenation is the term used for breaking up of words when they can’t fit on one line. There is a whole bunch of technical stuff involved in it and it can differ between languages. To take advantage of hyphenation in android, add the following to your TextView:
    • breakStrategy – simple, high_quality, balanced
    • hyphenationFrequency – full, normal, none
      • <TextView
              android:id="@+id/text_view_page"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:breakStrategy="high_quality"
              android:hyphenationFrequency="full"        
              android:text="@string/long_text" />

        Hyphenation Frequency = none

        Hyphenation Frequency = none

        Hyphenation Frequency - Full. Break Strategy - High Quality
        Hyphenation Frequency – Full. Break Strategy – High Quality
  2. Color Picker – When declaring a colour in your layouts, you can click on the colour icon on the side of the layout xml file. A new feature that I have discovered is the option to select the “Closest material colour”. This is such an awesome feature as I am always looking up the material colours from the website:  color picker in android studio
  3. Plurals – Sometimes you want to use a string but it needs to be a plural based on the number of items that you provide it. Instead of creating different strings yourself and manually switching between them, take advantage of the built in mechanism:
    <plurals name="how_many_oranges">
            <item quantity="zero">No oranges found</item>
            <item quantity="one">%d orange</item>
            <item quantity="other">%d oranges</item>
    </plurals>

    When using this string in your code, you would typically use it in the following way:

    String oranges = getResources().getQuantityString(R.plurals.how_many_oranges, 3, 3);

    See more about plurals here

  4. Digits – If you need an EditText to only accept certain characters, you can easily specify this in the layout. By using the android:digits field you can specify the characters that your EditText can accept. No additional code needed.
     <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:digits="1234mnp."
            android:id="@+id/editText"/>

     

  5. Great External Resources:

What Android things have you discovered this month? Leave a comment below!

Happy Holidays to everyone!

Monthly Android Morsels [November 2015]

Monthly Android Morsels [November 2015]

Just a small list of things related to Android development that I have found useful this month. Hope you find them useful too!

  • Android Design: A nice new way to edit your theme and see its effect in Android Studio. Click Tools -> Android -> Theme Editor
Android Theme Editor
Android Theme Editor
  • Android XML optimisation: Tired of creating dummy text strings in the strings.xml file? Or want to see things in the Design View but it’s supposed to be hidden in the real view?

You can use the nifty tools namespace to make things visible for design purposes but have no affect in your app. Add the tools namespace to your XML file and you can override things such as visibility and text. Even though android:visibility is set to gone, using tools:visibility to visible, the view will be visible in the Design View but not in the real implementation.Very handy for complex layouts.

https://gist.github.com/spongebobrf/fd3199c043e02e399b5c

http://tools.android.com/tips/layout-designtime-attributes

Using Design time
Using Design time attributes

What cool Android things have you discovered recently?

#AndroidMorsels