Skip to content

Instantly share code, notes, and snippets.

@kbshl
Created October 26, 2016 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbshl/abe537d4fd5cc2f877f7185e7034dba2 to your computer and use it in GitHub Desktop.
Save kbshl/abe537d4fd5cc2f877f7185e7034dba2 to your computer and use it in GitHub Desktop.
Toolbar with Appcelerator Titanium and Drawer Layout Module

Toolbar with Appcelerator Titanium and Drawer Layout Module

This is an example of how to activate the Toolbar for the Drawer Layout Module and create a Drawer Layout which overlaps the Android Actionbar respectively the Toolbar.

How this works

It is actually not the hardest work to get it to work. All happens through Android Theming and the correct tiapp.xml / Window configuration.

License

The MIT License (MIT)

Copyright (c) 2015 Manuel Lehner

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'#drawer': {
width: Ti.UI.FILL,
height: Ti.UI.FILL,
closeDrawerGestureMode: 'CLOSE_MODE_ALL',
openDrawerGestureMode: 'OPEN_MODE_BEZEL_PANNING_CENTERWINDOW',
showShadow: true,
shouldStretchDrawer: false,
leftDrawerWidth: Alloy.Globals.UI.drawer.width,
animationMode: 'ANIMATION_PARALLAX_FACTOR_3',
statusBarStyle: 'STATUSBAR_WHITE', // remember to set UIViewControllerBasedStatusBarAppearance to false in tiapp.xml
orientationModes: [Ti.UI.PORTRAIT]
}
'#drawer[platform=android]': {
drawerLayout: true,
arrowAnimation: true,
// Android wrapper window for drawer layout
window: {
theme: 'Theme.Hessentag.WithDrawer',
exitOnClose: true,
orientationModes: [Ti.UI.PORTRAIT],
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="FrameworkRoot.Theme.Dark" parent="Theme.AppCompat"></style>
<style name="FrameworkRoot.Theme.Light" parent="Theme.AppCompat.Light"></style>
<style name="FrameworkRoot.Theme.LightDarkBar" parent="Theme.AppCompat.Light.DarkActionBar"></style>
<style name="FrameworkRoot.Theme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar"></style>
<style name="FrameworkRoot.Theme" parent="Theme.AppCompat.Light"></style>
<style name="FrameworkRoot.Widget" parent="Theme.AppCompat.NoActionBar"></style>
<style name="Theme.ToolbarOverlay.Splash" parent="FrameworkRoot.Theme.Dark">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">@drawable/background</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowFullscreen">true</item>
</style>
<style name="Theme" parent="FrameworkRoot.Theme">
<item name="android:windowTranslucentStatus">true</item>
</style>
<style name="Theme.WithDrawer" parent="FrameworkRoot.Theme.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
<style name="Theme.ToolbarOverlay.Base" parent="Theme">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accent</item>
<item name="colorControlNormal">@color/primary</item>
<item name="colorControlHighlight">@color/highlight</item>
<item name="colorControlActivated">@color/activated</item>
<item name="colorSwitchThumbNormal">@color/highlight</item>
<item name="colorButtonNormal">@color/primary</item>
<item name="actionMenuTextColor">@color/actionMenuText</item>
<item name="actionBarTheme">@style/ToolbarOverlay.ToolbarTheme</item>
<item name="textAllCaps">false</item>
<item name="android:statusBarColor">@color/statusBar</item>
<item name="android:textColorPrimary">@color/textPrimary</item>
<item name="android:colorEdgeEffect">@color/highlight</item>
<item name="android:colorButtonNormal">@color/primary</item>
<item name="android:actionMenuTextColor">@color/actionMenuText</item>
<item name="android:actionBarTheme">@style/ToolbarOverlay.ToolbarTheme</item>
</style>
<style name="Theme.ToolbarOverlay.WithDrawer" parent="Theme.WithDrawer">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accent</item>
<item name="colorControlNormal">@color/primary</item>
<item name="colorControlHighlight">@color/highlight</item>
<item name="colorControlActivated">@color/activated</item>
<item name="colorSwitchThumbNormal">@color/highlight</item>
<item name="colorButtonNormal">@color/primary</item>
<item name="actionMenuTextColor">@color/actionMenuText</item>
<item name="actionBarTheme">@style/ToolbarOverlay.ToolbarTheme</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">@color/statusBar</item>
<item name="android:textColorPrimary">@color/textPrimary</item>
<item name="android:colorEdgeEffect">@color/highlight</item>
<item name="android:colorButtonNormal">@color/primary</item>
<item name="android:actionMenuTextColor">@color/actionMenuText</item>
<item name="android:actionBarTheme">@style/ToolbarOverlay.ToolbarTheme</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="Theme.ToolbarOverlay" parent="Theme.ToolbarOverlay.Base"></style>
<style name="ToolbarOverlay.ToolbarTheme" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColor">@color/actionMenuText</item>
<item name="android:textColorPrimary">@color/actionMenuText</item>
<item name="colorControlNormal">@color/actionMenuText</item>
<item name="colorControlHighlight">@color/highlight</item>
<item name="colorControlActivated">@color/activated</item>
<item name="android:colorControlNormal">@color/actionMenuText</item>
<item name="android:colorControlHighlight">@color/highlight</item>
<item name="android:colorControlActivated">@color/activated</item>
</style>
</resources>
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest android:installLocation="auto" android:versionCode="1475828150" android:versionName="0.1.0">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" />
<application android:theme="@style/Theme.ToolbarOverlay" android:largeHeap="true" android:debuggable="true">
<activity android:name=".ErfPlusActivity" android:label="@string/app_name" android:theme="@style/Theme.ToolbarOverlay.Splash"
android:configChanges="keyboardHidden|orientation|screenSize" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="org.appcelerator.titanium.TiActivity" android:configChanges="keyboardHidden|orientation|screenSize" />
<activity android:name="org.appcelerator.titanium.TiTranslucentActivity" android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/Theme.AppCompat.Translucent" />
<activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity" android:configChanges="screenSize" />
<activity android:name="ti.modules.titanium.media.TiVideoActivity" android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/Theme.AppCompat.Fullscreen" android:launchMode="singleTask" />
<service android:name="com.appcelerator.analytics.APSAnalyticsService" android:exported="false" />
</application>
</manifest>
</android>
<modules>
<module platform="android">com.tripvi.drawerlayout</module>
</modules>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment