layout怎么填充颜色(如何在安卓中为按钮添加颜色)

本文目录
- 如何在安卓中为按钮添加颜色
- 用JAVA语言编写在屏幕上绘制一个圆形并且分为思等分,分别填充4中不同的颜色
- java程序里的图形填充颜色,就是每个圆环的颜色2种颜色循环,可以看图
- android 里用shape画圆,怎么填充颜色
- layout为什么老有透明填充颜色
- android spinner怎么设置字体颜色
如何在安卓中为按钮添加颜色
安卓中为按钮添加颜色,只需要在xml布局文件中对按钮控件设置即可。
只需要设置background属性
《Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
/》
用JAVA语言编写在屏幕上绘制一个圆形并且分为思等分,分别填充4中不同的颜色
//看看行不行:
package com;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class Circle extends JFrame {
private ChessPanel chessPanel=new ChessPanel(550);
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
public static void main(String args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Circle thisClass = new Circle();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public Circle() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(700, 600);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(chessPanel, BorderLayout.CENTER);
}
return jContentPane;
}
class ChessPanel extends JPanel{
private int r;
public ChessPanel(int r){
this.r=r;
//setBackground(Color.RED);
setSize(300,200);
}
public void paintComponent(Graphics g){ //覆盖paintComponent()方法
super.paintComponent(g); //必须先调用父类的方法
g.setColor(Color.DARK_GRAY);
//g.fillOval(0, 0, r, r);
double a,b;
int x,y;
g.setColor(Color.GREEN);
g.fillArc(r/2, r/2, r/2, r/2, 0, 90);
g.setColor(Color.DARK_GRAY);
g.fillArc(r/2, r/2, r/2, r/2, 90, 90);
g.setColor(Color.red);
g.fillArc(r/2, r/2, r/2, r/2, 180, 90);
g.setColor(Color.yellow);
g.fillArc(r/2, r/2, r/2, r/2, 270, 90);
}
}
}
java程序里的图形填充颜色,就是每个圆环的颜色2种颜色循环,可以看图
主类不需要更改,只需改一下Circle.java我呢见
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import javax.swing.JPanel;
public class Circle extends JPanel
{
public void paintComponent( Graphics g )
{
super.paintComponent( g );
int numFlag=0;
for ( int topLeft = 0; topLeft 《 80; topLeft += 10 )
{
numFlag++;
if(numFlag%2==0)
g.setColor(Color.blue);//改变颜色
else
g.setColor(Color.white);//改变颜色
int radius = 160 - ( topLeft * 2 );
g.fillOval(topLeft + 10, topLeft + 25, radius, radius);//这是画圆
//g.fillArc( topLeft + 10, topLeft + 25, radius, radius, 0, 360 );
}
this.setBackground(Color.red);
}
}
android 里用shape画圆,怎么填充颜色
Android里面使用shape设置控件的外形,例如一些圆角、填充的背景颜色、以及一些渐变的效果等,所以设置填充颜色,可通过设置shape.xml文件里的如下属性:
《solid android:color="@color/common_red" /》
将shape文件放到android的button、textview组件上,就可以有填充背景颜色的效果,完整的代码如下:
1.shape.xml
《?xml version="1.0" encoding="UTF-8"?》
《shape
***隐藏网址***
android:shape="oval"
android:useLevel="false" 》
《solid android:color="@color/common_red" /》
《padding
android:left="2dp"
android:top="1dp"
android:right="2dp"
android:bottom="1dp" /》
《solid
android:color="@color/common_red" /》
《stroke
android:width="1dp"
android:color="@android:color/white" /》
《size android:width="15dp"
android:height="15dp" /》
《/shape》
2.把以上代码添加到drawable里面、通过background引用就可以了
《TextView
android:id="@ id/message_category_unread_count"
style="@style/comm_text_style_14_aaaaaa"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
android:background="@drawable/shape"
android:gravity="center"
android:textSize="@dimen/text_size_comment_20"
android:text="7"
android:textColor="@android:color/white" /》
效果如下图:
layout为什么老有透明填充颜色
因为RGB中的不透明度为0。Layout是属于动画专用名词,根据导演(或者其他人)所画的分镜表画出来的“设计图”,原画要根据Layout来画。layout老有透明填充颜色是因为RGB中的不透明度为0,只需调节不透明度即可。
android spinner怎么设置字体颜色
1、在layout中自定义spinner_item.xml,里面设置字体颜色大小等,然后代码中新建new ArrayAdapter《String》(this,R.layout.spinner_item);
然后setAdapter(xx);
2、自定义一个布局文件spinner_item.xml,这个就是spinner每一项的样式,一般是TextView,当然也可以是其他控件
3、也可以监听listview点击事件,在里面改变颜色,

更多文章:
html网页模板(网页制作设计模板-旅游网页该如何设计模板)
2025年9月29日 04:45
this love歌词taylor(求Taylor Swift的Love Story的歌词的中文翻译~)
2025年6月19日 16:30
span标签有内容却不显示(定义一个CSS,但是只有DIV可以显示出来,span等都无法显示)
2026年7月29日 21:00
void sort是什么意思(请各位说说void sort里的算法是什么意思)
2025年6月20日 00:15
学电脑软件开发哪个学校好(电脑软件开发去什么学校学习比较好)
2026年8月16日 18:45
subject都有什么意思(“subject ”是什么意思)
2026年8月15日 06:00
莫奈的网络解释莫奈的网络解释是什么?莫奈的解释莫奈的解释是什么
2025年7月29日 02:00
网页模板停用不能上报怎么办(请教一下,关于网页模板显示不出来的问题~~)
2025年10月22日 22:45
dateadd函数的语法参数(在VB6.0中,DateAdd函数中,用“w“,“y“与“d“,我怎么感觉都一样呀,都是天)
2026年2月21日 15:30
springfestival用in oron(the Spring Festival前用in还是on)
2026年8月28日 02:45
acquaintance歌曲(新年快乐英文歌除了happy new year还有那些)
2026年4月19日 03:15
constantly continuously(constantly怎么读)
2025年8月8日 18:15









