• Android 开发技巧总结(三)


    1.在界面中按返回键判断某个控件的可见性,如果可见,则用动画让其消失,应用并不退出。

    Onkeydown方法中:

    if(keyCode == 4){

    if(slidingMenu.getVisibility() == View.VISIBLE){

    //退出的动画

    AnimationSet animationSet = new AnimationSet(true);

    TranslateAnimation animation = new TranslateAnimation(0,-280, 0, 0);

    animation.setDuration(500);

    animationSet.addAnimation(animation);

    slidingMenu.startAnimation(animationSet);

    slidingMenu.setVisibility(View.GONE);

    return true; //如果控件在界面是可见的话,按返回键让其消失,应用并不退出

    }

    }

    2.控制界面的延时跳转

    public class WelcomeActivity extends Activity{

    private Handler mHandler = new Handler() {

    public void handleMessage(android.os.Message msg) {

    goMain();

    }};

    @Override

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

            setContentView(R.layout.welcome);

    }

    @Override

    protected void onResume() {

    super.onResume();

    mHandler.sendEmptyMessageDelayed(0, 3000);

    }

    /**

     * 跳转到主界面

     */

    private void goMain() {

    Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);

    startActivity(intent);

    this.finish();

    }}

    3.获取屏幕宽和高

    DisplayMetrics dm = new DisplayMetrics();
                    this.getWindowManager().getDefaultDisplay().getMetrics(dm);
                    screenWidth = dm.widthPixels;
                    screenHeight = dm.heightPixels;

    4.private protected public的区别

    public
    公共,加上这个修饰的类或属性,可以在同一个包或者别的包里面访问

    private
    私有的,加上这个修饰的类或属性,只能在同类里访问,同包和别的包不能访问

    protected
    保护,加上这个修饰的类或属性,只能在同类和同包访问,别的包不能访问

    5.在启动的activity中加入如下代码,实现应用的launcher效果。

    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.HOME" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.MONKEY" />
    </intent-filter>

    6.百度推送在最近应用中设置应用的推送状态。

    7.获取手机的唯一识别码

    TelephonyManager tm = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = tm.getDeviceId();

    8.百度推送高级设置中的自定义设置

    intent:#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.baidu.push.example/.PushDemoActivity;end

     

  • 相关阅读:
    Egret Inspector google 插件 浏览器报错的解决方案:
    egret 项目 支持 es6 解决方案
    promise-abortable
    BaseSocket
    【译】async/await 优点、陷阱以及如何使用 (经验总结)
    WebSocket 断线重连引入心跳的原因
    node js 项目: 采用typescript 编写的好文章
    创建Node.js TypeScript后端项目 demo
    vs code 提高工作效率的办法:
    cocos2d-x 贝塞尔曲线(Bezier)用法详解
  • 原文地址:https://www.cnblogs.com/kuaileyuyi/p/3853160.html
Copyright © 2020-2023  润新知