当前位置:操作系统 > 安卓/Android >>

android 特殊用法二

9.创建一个圆角图片
这个的主要原理其实就是利用遮罩,先创建一个圆角方框 然后将图片放在下面:

1.             Bitmap myCoolBitmap = ... ;    

2.                   int w = myCoolBitmap.getWidth(), h = myCoolBitmap.getHeight();    

3.                   Bitmap rounder = Bitmap.createBitmap(w,h,Bitmap.Config.ARGB_8888);    

4.                   Canvas canvas = new Canvas(rounder);       

5.                   Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG);    

6.                   xferPaint.setColor(Color.RED);    

7.                   canvas.drawRoundRect(new RectF(0,0,w,h), 20.0f, 20.0f, xferPaint);        

8.                   xferPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));  

1.             //然后呢实现    

2.             canvas.drawBitmap(myCoolBitmap, 0,0, null);    

3.             canvas.drawBitmap(rounder, 0, 0, xferPaint);   

10.在notification 上的icon上加上数字 给人提示有多少个未读

1.             Notification notification = new Notification (icon, tickerText, when);    

2.             notification .number = 4;  

11背景渐变:
首先建立文件drawable/shape.xml

1.             <?xml version="1.0" encoding="utf-8"?>    

2.             <shape xmlns:android ="http://schemas.android .com/apk/res/android " android :shape="rectangle">    

3.                 <gradient android :startColor="#FFFFFFFF" android :endColor="#FFFF0000"    

4.                         android :angle="270"/>    

5.             </shape>   

在该文件中设置渐变的开始颜色(startColor)、结束颜色(endColor)和角度(angle)

接着创建一个主题values/style.xml

1.             <?xml version="1.0" encoding="utf-8"?>    

2.             <resources>    

3.             <style name="NewTheme" parent="android :Theme">    

4.             <item name="android :background">@drawable/shape</item>    

5.             </style>    

6.             </resources>  

然后在AndroidManifest.xml文件中的application或activity中引入该主题,如:

1.             <activity android :name=".ShapeDemo" android :theme="@style/NewTheme">   

该方法同样适用于控件  http://17f8.cn/trackback.php?tbID=259&extra=9d45e9

12. 储存数据 当你在一个实例中保存静态数据,此示例关闭后 下一个实例想引用 静态数据就会为null,这里呢必须重写applition

1.             public class MyApplication extends Application{       

2.                private String thing = null;       

3.                public String getThing(){           

4.                  return thing;       

5.                  }       

6.                  public void setThing( String thing ){          

7.                   this.thing = thing;    }    

8.                   }    

9.                   public class MyActivity extends Activity {       

10.               private MyApplication app;       

11.               public void onCreate(Bundle savedInstanceState) {           

12.               super.onCreate(savedInstanceState);           

13.               app = ((MyApplication)getApplication());           

14.               String thing = app.getThing();       

15.               }    

      } 


摘自 LuoXianXiong,您的伙伴
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,