❶ 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();
}