导航:首页 > 软件资讯 > uniapp如何改变按钮的背景色

uniapp如何改变按钮的背景色

发布时间:2022-06-28 20:08:43

① ios开发怎么设置button的背景色

1.通过按钮的事件来设置背景色
- (void)viewDidLoad {
[super viewDidLoad];

UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(50, 200, 100, 50)];
[button1 setTitle:@"button1" forState:UIControlStateNormal];
button1.backgroundColor = [UIColor orangeColor];
[button1 addTarget:self action:@selector(button1BackGroundHighlighted:) forControlEvents:UIControlEventTouchDown];
[button1 addTarget:self action:@selector(button1BackGroundNormal:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
}

// button1普通状态下的背景色
- (void)button1BackGroundNormal:(UIButton *)sender
{
sender.backgroundColor = [UIColor orangeColor];
}

// button1高亮状态下的背景色
- (void)button1BackGroundHighlighted:(UIButton *)sender
{
sender.backgroundColor = [UIColor greenColor];
}

② 怎样改变BUTTON控件的背景色和字体色

新建一个对话框工程,在对话框中添加一个按钮,然后,从button类继承一个子类 CNewButton, 重载 PreSubclassWindow,修改按钮的属性 ModifyStyle( 0 , BS_OWNERDRAW ); ,告诉系统,用户手绘按钮; 然后再重载DrawItem,在这里边修改按钮的背景色,字体的颜色,修改lpDrawItemStruct参数的值,使用SetBkColor,设置按钮字体的颜色, SetTextColor设置字体的颜色, 使用FillRect可以填充按钮的背景色。设置完后,给对话框的按钮添加一个变量,基类就选择刚才创建的CNewButton

③ html 如何给button设置背景图片的同时设置按钮的背景色

这个可以用css来实现:background:url('imgurl')里面放图片地址,如果还想同时显示背景,需要用透明的PNG图片,如果不想图片重复显示需要设置背景不重复:background-repeat:no-repeat; 然后用background-color:red;设置按钮的背景颜色。下面例子是简写

<inputtype="button"style="background:url(./aa.png)no-repeatcenterred;width:200px;height:200px;">

④ uni-app radio的样式如何修改

前端中的input类标签中的radio和checkbox前面的选框的样式是不能改变的,但是这往往会造成我们在用起来时候样式的局限性,以下是改变样式的方法:隐藏默认样式,并将自己喜欢的样式作为背景图片显示;
首先:将默认样式隐藏,代码为
input[type = "radio"] {
display: none;
}

⑤ 安卓界面布局如何改变所有button的背景颜色

可以使用selector来实现Button的特效

main.xml

Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按下或者获得焦点Button会变不同颜色"
<SPAN style="COLOR: #ff0000">android:textColor="@color/button_text" </SPAN>/>
</LinearLayout>
www.2cto.com
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按下或者获得焦点Button会变不同颜色"
android:textColor="@color/button_text" />
</LinearLayout>

XML 文件保存在res/color/button_text.xml

Xml代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="#ffff0000"/> <!-- pressed -->
<item android:state_focused="true" android:color="#ff0000ff"/> <!-- focused -->
<item android:color="#ff000000"/> <!-- default -->
</selector>

背景选择器-selector

概述
在drawable/xxx.xml中配置,通过配置selector,可以使系统运行时根据控件对象的状态使用相应的图片、文字等。
selector中的常用属性
android:state_selected 控件选中状态,可以为true或false
android:state_focused 控件获得焦点状态,可以为true或false
android:state_pressed 控件点击状态,可以为true或false
android:state_enabled 控件使能状态,可以为true或false
android:state_checkable 控件可勾选状态,可以为true或false
android:state_checked 控件勾选状态,可以为true或false
注意:在状态描述中,第一个匹配当前状态的item会被使用。因此,如果第一个item没有任何状态特性的话,那么它将每次都被使用,所以默认的值必须总是在最后。
android:window_focused 应用程序窗口焦点状态,可以为true或false
android:color 定义特定状态的颜色
#rgb
#argb
#rrggbb
#aarrggbb
为16进制颜色。这个颜色由rgb值指定,可带alpha,必须以”#“开头,后面跟随alpha-red-green-blue信息,格式可以为:
使用selector设置背景
把下面的XML保存成.xml文件(比如list_item_bg.xml),运行时系统会根据ListView中列表项的状态来使用相应的背景图片。
drawable/list_item_bg.xml
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 默认时的背景图片 -->
<item android:drawable="@drawable/pic1" />

<!-- 没有焦点时的背景图片 -->
<item android:state_window_focused="false"
android:drawable="@drawable/pic1" />

<!-- 非触摸模式下获得焦点并单击时的背景图片 -->
<item android:state_focused="true" android:state_pressed="true"
android:drawable= "@drawable/pic2" />

<!-- 触摸模式下单击时的背景图片 -->
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/pic3" />

<!--选中时的图片背景 -->
<item android:state_selected="true"
android:drawable="@drawable/pic4" />

<!--获得焦点时的图片背景 -->
<item android:state_focused="true"
android:drawable="@drawable/pic5" />
</selector>

使用方法
第一种是在listview中配置android:listSelector=”@drawable/list_item_bg”
第二种是在listview的item中添加属性android:background=”@drawable/list_item_bg”
第三种是java代码中使用:
Drawable drawable = getResources().getDrawable(R.drawable.list_item_bg);
listview.setSelector(drawable);

注:列表有时候为黑的情况,需要加上下面的代码使其透明:
android:cacheColorHint="@android:color/transparent"

使用selector设置字体颜色
drawable/button_font.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="#FF0000" />
<item android:state_focused="true" android:color="#00FF00" />
<item android:state_pressed="true" android:color="#0000FF" />
<item android:color="#000000" />
</selector>

使用方法
android:textColor="@drawable/button_color"

更复杂的效果
还可以实现更复杂的效果,例如渐变等等。 drawable/button_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<!-- 定义当button 处于pressed 状态时的形态。-->
<shape>
<gradient android:startColor="#8600ff" />
<stroke android:width="2dp"
android:color="#000000" />
<corners android:radius="5dp" />
<padding android:left="10dp"
android:top="10dp"
android:bottom="10dp"
android:right="10dp"/>
</shape>
</item>
<item android:state_focused="true">
<!-- 定义当button获得 focus时的形态 -->
<shape>
<gradient android:startColor="#eac100"/>
<stroke android:width="2dp"
android:color="#333333"
color="#ffffff"/>
<corners android:radius="8dp" />
<padding android:left="10dp"
android:top="10dp"
android:bottom="10dp"
android:right="10dp"/>
</shape>
</item>
</selector>

使用方法
android:background="@drawable/button_color"
android:focusable="true"

⑥ 怎么去掉uniapp登录上面的默认样式

首先我们打开Hbuilder,新建一个项目,如下图所示
uniapp按钮样式怎么改
2

然后项目类型选择uni-app,项目名称随便起一个即可,如下图所示
uniapp按钮样式怎么改
3

接着我们就可以直接在vue文件中添加button了,通过type来声明按钮的样式,目前有的是primary,warn,default,如下图所示
uniapp按钮样式怎么改
4

运行以后我们可以看到三种不同的type对应了三种不同的颜色样式,如下图所示
uniapp按钮样式怎么改
5

另外还可以通过loding和disabled来定义按钮加载中和禁用的样式,如下图所示
uniapp按钮样式怎么改
6

在右侧我们可以看到用loading的按钮里面多了个加载动画,而用disabled的按钮是一种不能点击的状态
uniapp按钮样式怎么改
7

接着还可以通过plain来取消按钮的背景颜色,让它只有边框,如下图所示
uniapp按钮样式怎么改
8

运行以后我们就可以看到按钮只有边框了,背景变成白色的了,如下图所示
uniapp按钮样式怎么改
9

接下来还可以通过size来定义按钮的大小,如下图所示,mini代表的就是小按钮
uniapp按钮样式怎么改
10

最后我们就可以看到按钮变小了,这是经常会使用到的大小,如下图所示
uniapp按钮样式怎么改
END

⑦ ui怎么设置button被选中后的背景颜色

1,通过按钮的事件来设置背景色

- (void)viewDidLoad {
[super viewDidLoad];

UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(50, 200, 100, 50)];
[button1 setTitle:@"button1" forState:UIControlStateNormal];
button1.backgroundColor = [UIColor orangeColor];
[button1 addTarget:self action:@selector(button1BackGroundHighlighted:) forControlEvents:UIControlEventTouchDown];
[button1 addTarget:self action:@selector(button1BackGroundNormal:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
}

// button1普通状态下的背景色
- (void)button1BackGroundNormal:(UIButton *)sender
{
sender.backgroundColor = [UIColor orangeColor];
}

// button1高亮状态下的背景色
- (void)button1BackGroundHighlighted:(UIButton *)sender
{
sender.backgroundColor = [UIColor greenColor];
}

2,通过把颜色转换为UIImage来作为按钮不同状态下的背景图片

- (void)viewDidLoad {
[super viewDidLoad];

UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectMake(170, 200, 100, 50)];
[button2 setTitle:@"button2" forState:UIControlStateNormal];
[button2 setBackgroundImage:[self imageWithColor:[UIColor redColor]] forState:UIControlStateNormal];
[button2 setBackgroundImage:[self imageWithColor:[UIColor grayColor]] forState:UIControlStateHighlighted];
[self.view addSubview:button2];
}

// 颜色转换为背景图片
- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();

(context, [color CGColor]);
CGContextFillRect(context, rect);

UIImage *image = ();
UIGraphicsEndImageContext();

return image;
}

⑧ 请指教:如何改变button的背景色

换一个TBitbtm,设一下Glyph属性实现起来比较简单,试试看阿

⑨ 如何改变Button颜色

调色板类QPallete提供了颜色角色(color roles)概念,是指当前GUI界面中颜色的职责,通过枚举变量QPalette::ColorRole来定义,比较常用的颜色角色有:
QPalete::Window,通常指窗口部件的背景色;
QPalette:WindowText,通常指窗口不见的前景色;
QPalette::Base,指文本输入窗口部件(比如QtextEdit,QLinedit等)的背景色.
QPalette::Text,与QPalette::Base一块使用,指文本输入窗口部件的前景色;
QPalette::Button,指按钮窗口部件的背景色;
QPalette::ButtonText,指按钮窗口部件的前景色.

例:

QPalette pal = pushButtonCancel->palette();
pal.setColor(QColorGroup::ButtonText,QColor(255,0,0));
pushButtonCancel->setPalette(pal);

按钮pushButton的字体颜色为红色

⑩ button 点击后怎么改变背景颜色

HTML中点击按钮更改DIV背景颜色可以用JavaScript脚本实现: function changecolor(){ document.getElementById("div").style.background="red"; //更改为红色}

阅读全文

与uniapp如何改变按钮的背景色相关的资料

热点内容
一堆文件夹怎么弄出来 浏览:743
博途如何编译硬件 浏览:418
fortran程序pdf 浏览:504
电池消耗算法 浏览:394
服务器中断连接怎么处理 浏览:222
上世纪互联网不发达程序员很难 浏览:841
语音识别android开源 浏览:762
地埋式垃圾压缩中转站 浏览:902
apachehttpdlinux 浏览:944
快递员中通app预付款是什么 浏览:843
java路径转义 浏览:857
keytool加密算法 浏览:131
笑脸图案的APP相机是什么软件 浏览:249
app软件为什么会被下架 浏览:980
从内存到硬盘的命令是 浏览:52
程序员的爸爸们的发型 浏览:123
魔兽世界伤害压缩是怎么压的 浏览:976
压缩机型号hp 浏览:958
配音虚弱的程序员 浏览:61
8岁小学生程序员编程 浏览:256