Android实用小技巧

1、去掉所有Activity界面的标题栏

  修改AndroidManifest.xml 
  在application 标签中添加android:theme="@android:style/Theme.NoTitleBar"

 

2、去掉所有Activity界面的TitleBar 和StatusBar 

  修改AndroidManifest.xml 

  在application 标签中添加 

  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

 

3、代码混淆(防止反编译)

 

在project.properties中添加

proguard.config=proguard.cfg

 

4、APK签名

 

导出:

1.Mainifest文件导出未签名的apk

2.右键Aandroid Toools 导出签名和未签名的apk

签名:

把keystore文件和未签名apk放到同一文件夹下

命令行进入改目录

输入:jarsigner -verbose -keystore ericsson.keystore cardbox.apk eri

然后输入密码即可 

 

5、点击EditText时文字全选

添加属性:android:selectAllOnFocus="true"

 

6、单位及屏幕适配

根据google的推荐,像素统一使用dip,字体统一使用sp
支持不同屏幕:
<supports-screens android:largeScreens="true"
       android:normalScreens="true" android:anyDensity="true"
       android:smallScreens="true"></supports-screens>

 

7、获取屏幕分辨率大小

DisplayMetrics dm=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
displayWidth=dm.widthPixels;//屏幕宽度
dispalyHeight=dm.heightPixels;//屏幕高度

 

8、自定义标题栏

this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  
setContentView(R.layout.main);  
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); 


R.layout.custom_title为自定义标题栏样式


在values下新建style.xml文件
<?xml version="1.0" encoding="utf-8"?>  
<resources>    
    <style name="MyTheme" parent="android:Theme">         
        <item name="android:windowTitleBackgroundStyle">@null</item>          
    </style>       
</resources>   


<activity android:name=".CustomTitleActivity" android:theme="@style/MyTheme" >

猜你喜欢

转载自duchengjiu.iteye.com/blog/2067847