I am trying to make custom button with xml layout, and I want to call that layout file on my button background. So how to use my xml layout file in Titanium Android, as in native I use to set button background from xml layouts file
background:"@drawable/custom_button" // where custom_button is an xml file present in drawable folder of native android.Actually reason for making custom button is to maintain 3 state as tabbar.
1 Answer
You can do this by putting all the resources to /Platform/android/res/drawable. These resources will be copied to res/drawable folder when you build your project. Then to give the reference of this drawable xml file you can do following.
var tab1 = Ti.UI.createTab({ title : 'Tab1', window : selectProductWin, icon : globals.isIos ? '/images/tab1.png' : Ti.App.Android.R.drawable.tabbar1 , });tabbar1 is the drawable xml file which is into the /Platform/android/res/drawable folder. tabbar1.xml will look like below
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/tab1act" android:state_pressed="false" android:state_selected="true"/> <item android:drawable="@drawable/tab1inact"/> </selector>Here tab1act and tab1inact are the images which is into the same folder where we have putted tabbar1.xml ie. /Platform/android/res/drawable folder
Your Answer
Think you can help? Login to answer this question!