Sencha touch mimics the instance code for TabBar the tabpanel navigation bar
- 2020-03-26 21:39:11
- OfStack
Written based on sencha touch 2.2
Code:
Ext.define('ux.TabBar', {
alternateClassName: 'tabBar',
extend: 'Ext.Toolbar',
xtype: 'tabBar',
config: {
docked: 'bottom',
cls: 'navToolbar',
layout: {
align: 'stretch'
},
defaults: {
flex: 1
},
//The selected button
selectButton: null
},
initialize: function () {
var me = this;
me.callParent();
//Listen for button click events
me.on({
delegate: '> button',
scope: me,
tap: 'onButtonTap'
});
},
//Update the selected button
updateSelectButton: function (newItem, oldItem) {
console.log(oldItem);
if (oldItem) {
oldItem.removeCls('x-tabBar-pressing');
}
if (newItem) {
newItem.addCls('x-tabBar-pressing');
}
},
//When the button is clicked
onButtonTap: function (button) {
this.setSelectButton(button);
},
onItemAdd: function (item, index) {
if (!this.getSelectButton() && item.getInitialConfig('selected')) {
this.setSelectButton(item);
}
this.callParent(arguments);
}
});
Required CSS:
.navToolbar {
padding:0;
}
.navToolbar .x-button {
border:0;
margin:0;
border-right:1px solid #585B5B;
border-radius:0;
padding:0;
}
.navToolbar .x-button .x-button-label {
font-weight:normal;
color:White;
font-size:0.6em;
}
.navToolbar .x-tabBar-pressing {
background-image:none;
background-color:#0f517e;
background-image:-webkit-gradient(linear,50% 0%,50% 100%,color-stop(0%,#0a3351),color-stop(10%,#0c4267),color-stop(65%,#0f517e),color-stop(100%,#0f5280));
background-image:-webkit-linear-gradient(top,#0a3351,#0c4267 10%,#0f517e 65%,#0f5280);
background-image:-moz-linear-gradient(top,#0a3351,#0c4267 10%,#0f517e 65%,#0f5280);
background-image:-o-linear-gradient(top,#0a3351,#0c4267 10%,#0f517e 65%,#0f5280);
background-image:linear-gradient(top,#0a3351,#0c4267 10%,#0f517e 65%,#0f5280);
}
Use:
Ext.define('app.view.MyBar', {
alternateClassName: 'myBar',
extend: 'ux.TabBar',
xtype: 'myBar',
config: {
items: [
{
xtype: 'button',
text: ' The questionnaire survey ',
//Only the first set of properties is valid
selected: true
},
{
xtype: 'button',
text: ' My points '
},
{
xtype: 'button',
text: ' The lottery of the hall '
},
{
xtype: 'button',
text: ' Lucky number '
},
{
xtype: 'button',
text: ' More and more '
}]
}
});
Effect:
< img border = 0 SRC = "/ / files.jb51.net/file_images/article/201310/20131024161754166.png" >