❶ android移动开发图片int型表示
您好,请参考本段落:
/**
* 程序入口
*
* @author talentClass
*/
public class MainActivity extends AppCompatActivity implements GameLayout.Game2048Listener {
public static final String SCORE = "score";
/**
* 模式:false为数字,true为图片
*/
private boolean bType;
private TextView tvScore, tvMaxScore; // 当前分数、最高分
private Button btnType, btnRestart; // 设置类型、重新开始
private GameLayout mGameLayout; // 自定义View容器
// 放置图片的数组
private int[] mImages = {R.mipmap.image1, R.mipmap.image2, R.mipmap.image3, R.mipmap.image4, R.mipmap.image5, R.mipmap.image6,
R.mipmap.image7, R.mipmap.image8, R.mipmap.image9, R.mipmap.image10, R.mipmap.image11};
❷ android怎么调节屏幕色彩
Android中颜色是由透明度(alpha)和红绿蓝(RGB)定义的,两种编码方式:
1、八位十六进制数,例如FFEEDDCC,FF代表透明度(完全不透明),EE代表红色(值越大红色越深),DD代表绿色,CC代表蓝色;
2、六位十六进制数,同上;
注意:六位编码在XML中默认不透明(FF),在代码中默认透明(00);在代码中设置颜色,可以直接填八位的十六进制数值,如setTextColor(0xff00ff00);,也可以通过Color.rgb(int red, int green, int blue)和Color.argb(int alpha, int red, int green, int blue)来指定颜色。
如果在代码中使用colors.xml中设置的颜色,可按如下方式获取setTextColor(getResources().getColor(R.color.black));
❸ Android 中代码定义颜色的几种方式
Android开发中颜色的自定义方法
1、使用Color类的常量,如:
int color = Color.BLUE; // 创建一个蓝色 是使用Android提供的颜色 int color = Color.RED; int color = Color.WHITE; 2、通过ARGB构建,如:
int color = Color.argb ( 127, 255, 0, 255 ); // 半透明的紫色
其中第一个参数表示透明,0表示完全透明,255(ff)表示完全不透明;后三位分别代表RGB的值了。 3、使用XML资源文件来定义颜色
该方法扩展性好,便于修改和共享,如在values目录下创建一个color.xml: <?xml version=” 1.0” encoding=”utf -8”> <resources>
<color name=”mycolor”> #7fff00ff</color> </resources>
定义了一个名为mycolor的颜色,在别的地方就可以通过引用mycolor来获取该颜色值,如textView定义中:
android:textColor= "@drawable/mycolor"
java代码中可以使用ResourceManager类中的getColor来获取该颜色: int color = getResources().getColor(R.color.mycolor);
这与第二种方法得到的值是一样的,getResources()方法返回当前活动Activity的ResourceManager类实例。
说明:XML定义方法接受6位和8位两种表示法,而且开头必须是#,8位定义时前两位表示透明。 4、直接定义色值,如: int color = 0xff00ff00;
这种方法必须使用0x开头,而不是用我们常用的#。与方法3不一样,值也必须用8位表示 ,不接受6位的颜色表示。分组一下0x|ff|ff00ff,0x是代表颜色整数的标记,ff是表示透明度,ff00ff表示RGB颜色值。
=======================
补充一点Android布局中背景图片的设置(编辑LinearLayout):
* 可以使用纯色:android:background="@drawable/mycolor" (XML资源文件中定义的颜色)
* 也可使用图片:android:background="@drawable/bg" (需要将一个名为bg.jpg或png的图片拷贝到res/drawable-hdpi目录下)。
❹ 如何颜色整数转换为Android的十六进制字符串
#include#include#includeintzh(chars[]){inti,m,temp=0,n;m=strlen(s);//十六进制是按字符串传进来的,所以要获得他的长度for(i=0;i='A'&&s[i]='a'&&s[i]<='f')n=s[i]-'a'+10;elsen=s[i]-'0';temp=temp*16+n;}returntemp;}intmain(){chars[10];gets(s);intn=zh(s);printf("%d\n",n);return0;}
❺ Android"640.00"怎么转为int类型
mageView imageview = (ImageView) this.findViewById(R.id.imageview_welcome);
double d1 = 640.00/1136.00;
double d2 = (double)screenWidth/(double)screenHeight;
if(d1>d2){
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) imageview.getLayoutParams();
params.height = screenHeight;
params.width = (int) (640.00*((double)screenHeight/1136.00));
int m = (int)((double)((double)640.00*((double)screenHeight/1136.00))-screenWidth)/2;
params.leftMargin = -m;
params.rightMargin = -m;
imageview.setLayoutParams(params);
}else if(d2>d1){
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) imageview.getLayoutParams();
params.width = screenWidth;
params.height = (int) ((double)1136.00*((double)screenWidth/640.00));
int m = (int)((double)((double)1136.00*((double)screenWidth/640.00))-screenHeight)/2;
params.topMargin = -m;
params.bottomMargin = -m;
imageview.setLayoutParams(params);
}
————————————————
❻ android中如何设置上下文菜单颜色
public class ContextMenuActivity extends Activity
{
private final static int ITEM0 = Menu.FIRST;
private final static int ITEM1 = Menu.FIRST + 1;
private final static int ITEM2 = Menu.FIRST + 2;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.context_menu);
setTitle("单击Menu键看到效果!");
textView = (TextView) findViewById(R.id.tv1);
this.registerForContextMenu(textView);// 将上下文注册到TextView
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
{
menu.add(0, ITEM0, 0, "红色字体");
menu.add(0, ITEM1, 0, "绿色字体");
menu.add(0, ITEM2, 0, "白色字体");
}
@Override
public boolean onContextItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case ITEM0:
textView.setTextColor(Color.RED);
break;
case ITEM1:
textView.setTextColor(Color.GREEN);
break;
case ITEM2:
textView.setTextColor(Color.WHITE);
break;
default:
break;
}
return true;
}
}
❼ 如何设置Android中控件的颜色透明度
设置Android中控件的颜色透明度,可自由设置在layout里也可以在activity里
eclipse
1
#ff000000 此为16进制颜色代码,
前2位ff为透明度,后6位为颜色值(000000为黑色,ffffff为白色,可以用ps等软件获取)。
2
透明度分为256阶(0-255),计算机上用16进制表示为(00-ff)。透明就是0阶,不透明就是255阶,如果50%透明就是127阶(256的一半当然是128,但因为是从0开始,所以实际上是127)。
3
10进制的255换算成16进制是ff,127换算成16进制是7f,#7f000000 代表50%透明度的黑色。 (写成#50000000当然是不行的)进制转换可使用win7自带计算器(转为科学型)。例:25%透明度的一种红色“#3ff70000
❽ android中怎么实现指示灯颜色
很多Android手机上都配有LED灯,比如HTC的手机在充电、新来短信等时候都会有响应的指示,其实很简单的这都是NotificationManager的一些参数而已,下面Android123给大家说下如何通过代码控制LED灯的闪烁,因为有些机型没有LED灯或颜色种类较少,发布时需要真机观察。
复制代码代码如下:
final int ID_LED=19871103;
NotificationManager nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification();
notification.ledARGB = 0xFFFFFF; //这里是颜色,我们可以尝试改变,理论上0xFF0000是红色,0x00FF00是绿色
notification.ledOnMS = 100;
notification.ledOffMS = 100;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
nm.notify(ID_LED, notification);
nm.cancel(ID_LED);
❾ android 从一个颜色渐变到另外一个颜色
画图的话
LinearGradientlg=newLinearGradient(statrX,statrY,statrX,
stopY,newint[]{Color.rgb(5,254,4),
Color.rgb(189,254,0),Color.rgb(255,142,4),
Color.rgb(248,0,1),Color.rgb(148,0,78),
Color.rgb(121,2,43)},newfloat[]{0,0.2f,0.4f,
0.6f,0.8f,1.0f},TileMode.MIRROR);
//这个是y轴上的变化从绿色到橘黄色到大红色到黑红色。。。
//float数组相当于把Y轴平分为5段
paint.setShader(lg);
线程的话
Handlerhandler=newHandler(){
publicvoidhandleMessage(android.os.Messagemsg){
switch(msg.what){
case100:
textView.setTextColor(colors[msg.arg1]);//颜色的数组,和下面的for的次数要等
break;
default:
break;
}
};
};
privatevoidhuatu(){
//TODOAuto-generatedmethodstub
newThread(newRunnable(){
@Override
publicvoidrun(){
//TODOAuto-generatedmethodstub
try{
for(inti=0;i<5;i++){
Thread.sleep(200);
Messagemessage=newMessage();
message.what=100;
message.arg1=i;
handler.sendMessage(message);
}
}catch(InterruptedExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}).start();
}