Well, after doing some work-related Android development I went to see to fitting a SlidingDrawer to some basic content but alas things have changed since I first used it for the Letchworth app. Though deprecation doesn’t mean immediate incompatibility it does signal that it can be dropped from being supported at all in the near future.
SlidingDrawer in action – sliding out extra content
Naturally the Android developer suggestion was to just resurrect the code as its source code is available, but I kept hitting issues that weren’t elaborated in existing tips online. After finally collecting enough of a trail from various sources, I think I have all the steps you would need in one place (assuming that you’ve experienced using SlidingDrawer):
- Copy SlidingDrawer into your package. I will for this example copy and rename appropriately the class to
MySlider
and place it in package com.foo.prettyui
- Add to
/res/values/attr.xml
a copy of the sliding drawer styleables. For ease of reuse, refer the name value to your class name – in this case ‘MySlider’
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<declare-styleable name="MySlider">
<attr name="handle" format="reference" />
<attr name="content" format="reference" />
<attr name="orientation" format="integer" />
<attr name="bottomOffset" format="dimension" />
<attr name="topOffset" format="dimension" />
<attr name="allowSingleTap" format="boolean" />
<attr name="animateOnClick" format="boolean" />
</declare-styleable>
</resources> |
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<declare-styleable name="MySlider">
<attr name="handle" format="reference" />
<attr name="content" format="reference" />
<attr name="orientation" format="integer" />
<attr name="bottomOffset" format="dimension" />
<attr name="topOffset" format="dimension" />
<attr name="allowSingleTap" format="boolean" />
<attr name="animateOnClick" format="boolean" />
</declare-styleable>
</resources>
- Change your cloned code into using the styleable attributes that you have just declared – ie: replace all instances of
R.styleable.SlidingDrawer_bottomOffset
to R.styleable.MySlider_bottomOffset
in MySlider.java. At the end of this stage you should check if it all compiles – hopefully things are fine which would mean it’s ready to use
- How to use it: you need to add the package MySlider is in by adding it as another namespace at the top of with the xml declaration (alongside the android schema). For this example
xmlns:prettyui="http://schemas.android.com/apk/res/com.foo.prettyui"
I’ve declared prettyui
as my new namespace – you will need to use this for any of the SlidingDrawer MySlider styleable atributes – namely handle
and content
(the minimum required), so to continue:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:prettyui="http://schemas.android.com/apk/res/com.foo.prettyui"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
..OTHER STUFF..
<com.foo.prettyui.MySlider
android:layout_alignParentBottom="true"
android:id="@+id/questionanswer_related_drawer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
prettyui:handle="@+id/slider_button"
prettyui:content="@+id/slider_section">
..YOUR SLIDING DRAWER STUFF..
..WHICH SHOULD INCLUDE 2 LAYOUTS WITH THE IDS AS STATED IN HANDLE/CONTENT..
</com.foo.prettyui.MySlider>
..MORE STUFF..
</RelativeLayout> |
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:prettyui="http://schemas.android.com/apk/res/com.foo.prettyui"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
..OTHER STUFF..
<com.foo.prettyui.MySlider
android:layout_alignParentBottom="true"
android:id="@+id/questionanswer_related_drawer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
prettyui:handle="@+id/slider_button"
prettyui:content="@+id/slider_section">
..YOUR SLIDING DRAWER STUFF..
..WHICH SHOULD INCLUDE 2 LAYOUTS WITH THE IDS AS STATED IN HANDLE/CONTENT..
</com.foo.prettyui.MySlider>
..MORE STUFF..
</RelativeLayout>
- The above layout attributes can be reused if you decide to extend your SlidingDrawer, say if you wish to allow it to set its height to
wrap_content
So, from my phone (API level 17) onwards SlidingDrawer is officially dead. Long live SlidingDrawer!