微信小程序使用Vant

微信小程序使用Vant,第1张

将 app.json 中的 "style": "v2" 去除,小程序的新版基础组件强行加上了许多样式,难以覆盖,不关闭将造成部分组件样式混乱。

开发者工具创建的项目,miniprogramRoot 默认为 miniprogram,package.json 在其外部,npm 构建无法正常工作。需要手动在 project.config.json 内添加如下配置,使开发者工具可以正确索引到 npm 依赖的位置。

打开微信开发者工具,点击  工具 ->构建 npm ,并勾选  使用 npm 模块  选项,构建完成后,

到 全局配置 app.json 中注册引入组件,详见 快速上手 。

支持default、primary、info、warning、danger五种类型,默认为default。  格式:

通过plain属性将按钮设置为朴素按钮

设置hairline属性可以开启 0.5px 边框,基于伪类实现。

通过disabled属性来禁用按钮,此时按钮的bind:click事件不会触发。

通过loading属性来设置加载按钮   loading-type="spinner"   loading-text="加载中..."

通过icon属性设置按钮图标,支持 Icon 组件里的所有图标,也可以传入图标 URL。

label     输入框左侧文本

type    可设置为任意原生类型, 如 number   idcard    textarea    digit

readonly  是否只读

custom-style    自定义样式

autosize    是否自适应内容高度,只对 textarea 有效,可传入对象,如 { maxHeight: 100, minHeight: 50 },单位为px

show :是否显示 

onClose 点击其他位置,关闭d出层

position            可以设置为top、bottom、left、right。

Picker 选择器 需要配合d出层使用

<van-picker columns="{{ columns }}" bind:change="onChange" />

columns 对象数组,配置每一列显示的数据

onChange(e)    有默认参数 e 

value-key    选项对象中,文字对应的 key 通常用于对象数组

show-toolbar    是否显示顶部栏

defaultIndex     初始选中项的索引,默认为 0  不是双向绑定 需要自己改变defaultIndex  的值  需要渲染两次

/*计算器*/

import java.awt.*

import javax.swing.*

import javax.swing.border.*

import java.awt.event.*

public class Calculator implements ActionListener{

JFrame frame

JPanel panel

JTextField tfShow/*定义显示文本框*/

JButton b1[]=new JButton[10]/*数字按钮*/

JButton b2[]=new JButton[6]/* *** 作按钮*/

boolean isNumber/*判断是否输入多位数字的变量*/

double number/*存储输入数值、显示结果的变量*/

double result/*存储中间运算结果的变量*/

char operator/*存储当前 *** 作符的成员变量*/

public Calculator(){

frame=new JFrame("计算器")

frame.setSize(300,300)/*指定框架窗口的大小*/

frame.setResizable(false)/*使框架窗口不可改变大小*/

JPanel contentPane=(JPanel)frame.getContentPane()

contentPane.setBorder(new EmptyBorder(20,20,20,20))/*绘制框架的指定大小的空透明边框*/

tfShow=new JTextField("0",25)/*指定属性的文本域*/

tfShow.setHorizontalAlignment(JTextField.RIGHT)/*设置文本域中文本的对齐方式*/

isNumber=true/*初始值设置*/

number=0/*初始值设置*/

result=0/*初始值设置*/

operator=' '/*初始值设置*/

for(int i=0i<b1.lengthi++){

b1[i]=new JButton(Integer.toString(i))/*创建数字按钮*/

b1[i].setActionCommand(Integer.toString(i))

b1[i].addActionListener(this)

b1[i].setForeground(Color.blue)

}

String bs[]={"/","*","-","C","+","="}

for(int i=0i<b2.lengthi++){

b2[i]=new JButton(bs[i])/*创建 *** 作按钮*/

b2[i].setActionCommand(bs[i])

b2[i].addActionListener(this)

b2[i].setForeground(Color.red)

}

panel=new JPanel()

panel.setLayout(new GridLayout(4,5))

panel.add(b1[1])

panel.add(b1[2])

panel.add(b1[3])

panel.add(b2[0])

panel.add(b1[4])

panel.add(b1[5])

panel.add(b1[6])

panel.add(b2[1])

panel.add(b1[7])

panel.add(b1[8])

panel.add(b1[9])

panel.add(b2[2])

panel.add(b1[0])

panel.add(b2[3])

panel.add(b2[4])

panel.add(b2[5])

frame.add(tfShow,BorderLayout.NORTH)/*将文本框放置在框架上方*/

frame.add(panel,BorderLayout.CENTER)/*将装有按钮组的panel放在框架的中心*/

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)/*设置框架窗口的默认窗口关闭 *** 作*/

frame.setVisible(true)/*设置框架可见*/

}

public double getDisplay(){/*返回要显示的结果*/

return number

}

public void reDisplay(){/*刷新文本域的内容*/

tfShow.setText(""+getDisplay())

}

/*对输入数字的处理*/

public void numberProcess(int num){

if(isNumber&&num!=0){

String s1=Integer.toString(num)

String s2=Integer.toString((int)(this.number))

this.number=Double.parseDouble(s2+s1)/*对多位数字的处理*/

}else{

this.number=num

}

isNumber=true/*输入连续数字(即多位数字)时为真*/

}

public void operationProcess(char operator){/*根据输入的 *** 作符改变当前 *** 作符*/

switch(operator){

case '-':

this.operator='-'

break

case '+':

this.operator='+'

break

case '*':

this.operator='*'

break

case '/':

this.operator='/'

break

}

result=number

isNumber=false/*输入 *** 作符时表示输入连续数字的标记变量为假*/

}

public void clear(){

number=0

result=0

}

public void equal(){/*计算运算结果*/

switch(operator){

case '-':

result=result-number

break

case '+':

result=result+number

break

case '*':

result=result*number

break

case '/':

result=result/number

break

case ' ':

result=number

break

}

number=result/*把运算结果赋值给显示变量*/

isNumber=false

operator=' '

}

public static void main(String args[]){

Calculator cal=new Calculator()/*创建计算器*/

}

public void actionPerformed(ActionEvent e){

String command=e.getActionCommand()/*获取按钮激发的 *** 作事件的命令名称*/

char c=command.charAt(0)/*将按钮命令名称的第一个字符赋值给一个字符c*/

switch(c){

case '1':

case '2':

case '3':

case '4':

case '5':

case '6':

case '7':

case '8':

case '9':

case '0':

int number=Integer.parseInt(command)

numberProcess(number)/*输入数字的处理*/

break

case '+':

case '-':

case '*':

case '/':

operationProcess(c)/*算数运算符的处理*/

break

case '=':equal()break/*计算运算结果*/

case 'C':clear()break/*清零*/

}

reDisplay()/*在文本域中显示信息*/

}

}

这是我做的一个计算器:运行截图

修改适配器的布局图片就可以了。

ArrayAdapter<String>adapter =

new ArrayAdapter<String>( this,

android.R.layout.simple_spinner_item)//这个布局修改。

Spinner位于 android.widget包下,每次只显示用户选中的元素,当用户再次点击时,会d出选择列表供用户选择,而选择列表中的元素同样来自适配器。Spinner是View类得一个子类。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11228032.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-14
下一篇2023-05-14

发表评论

登录后才能评论

评论列表(0条)

    保存