当前位置:  编程技术>移动开发
本页文章导读:
    ▪关于荧幕解锁的实例        关于屏幕解锁的实例 AndroidManifest.xml加两个权限 Java代码  <uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>   <uses-permission android:name="android.permission.WAKE_LOCK">&.........
    ▪ 自定义题目Title        自定义标题Title Java代码  requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  setContentView(R.layout.my);   getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,                       R.layout.my_title);  request.........
    ▪ Dialog舒卷动画效果       Dialog伸缩动画效果 ViewScale.java: Java代码  public class ViewScale extends Activity implements OnClickListener {         private LinearLayout mLayout;       private Animation mScaleIn, mScaleOut;         @Override      p.........

[1]关于荧幕解锁的实例
    来源: 互联网  发布时间: 2014-02-18
关于屏幕解锁的实例
AndroidManifest.xml加两个权限
Java代码 
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>  
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission> 


<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>

Android屏幕解锁:
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE); 
        KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(""); 
        keyguardLock.disableKeyguard();
Android 点亮屏幕:
PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE); 
WakeLock mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.SCREEN_DIM_WAKE_LOCK, "SimpleTimer"); 
mWakelock.acquire(); 
//... 
mWakelock.release();//关闭
Java代码 
import android.app.KeyguardManager;    
import android.content.Context;    
import android.os.PowerManager;    
     
public class ScreenLockManager {    
   private Context mContext;    
   private KeyguardManager.KeyguardLock mKeyguardLock;    
   private boolean isScreenLock;    
   private PowerManager.WakeLock mWakelock;    
   public ScreenLockManager(Context context) {    
     mContext = context;    
   }    
   public void getUnlock() {    
     // acquire wake lock    
     PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);    
     mWakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "SimpleTimer");    
     mWakelock.acquire();    
     // unlock screen    
     KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);    
     mKeyguardLock = km.newKeyguardLock(Log.TAG);    
     if (km.inKeyguardRestrictedInputMode()) {    
       mKeyguardLock.disableKeyguard();    
       isScreenLock = true;    
     } else {    
       isScreenLock = false;    
     }    
   }    
   public void releaseUnlock() {    
     // release screen    
     if (isScreenLock) {    
       mKeyguardLock.reenableKeyguard();    
       isScreenLock = false;    
     }     
     // release wake lock    
     if (mWakelock.isHeld()) {    
       mWakelock.release();    
     }    
   }    
------------    
public class Log {    
           public static final String TAG = "SimpleTimer";    
           public static void v(String msg){    
             android.util.Log.v(TAG, msg);    
           }    
           public static void d(String msg){    
             android.util.Log.d(TAG, msg);    
           }    
           public static void e(String msg){    
             android.util.Log.e(TAG, msg);    
           }    
           public static void e(Exception e){    
             android.util.Log.e(TAG, e.getMessage(),e);    
           }    
         }   

    
[2] 自定义题目Title
    来源: 互联网  发布时间: 2014-02-18
自定义标题Title
Java代码 
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  setContentView(R.layout.my);  
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,  
                    R.layout.my_title); 

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.my);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
    R.layout.my_title);


my_title.xml:
Java代码 
<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout android:id="@+id/header" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content" android:layout_width="fill_parent" 
    android:background="#d4e9a9">  
 
    <ImageView android:src="/blog_article/@drawable/jetpack/index.html" 
        android:layout_width="wrap_content"   
        android:layout_alignParentLeft="true" 
        android:layout_centerVertical="true"   
        android:id="@+id/back" 
        android:layout_height="wrap_content"   
        android:layout_alignParentTop="true" />  
 
    <TextView android:id="@+id/title"   
        android:layout_width="wrap_content" 
        android:gravity="center_vertical"   
        android:textSize="20px" 
        android:textColor="#ffffff"   
        android:layout_alignParentRight="true" 
        android:text="New Title"   
        android:background="#a5c639" 
        android:layout_height="wrap_content"   
        android:layout_alignParentTop="true" 
        android:padding="9dip"   
        android:layout_margin="5dip" />  
</RelativeLayout> 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/header"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:background="#d4e9a9">

<ImageView android:src="/blog_article/@drawable/jetpack/index.html"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:id="@+id/back"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />

<TextView android:id="@+id/title"
    android:layout_width="wrap_content"
android:gravity="center_vertical"
android:textSize="20px"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:text="New Title"
android:background="#a5c639"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:padding="9dip"
android:layout_margin="5dip" />
</RelativeLayout>


jetpack.xml:

Java代码 
<?xml version="1.0" encoding="utf-8"?>  
<selector xmlns:android="http://schemas.android.com/apk/res/android">  
 
    <item android:state_pressed="false" 
        android:drawable="@drawable/jetpack_normal" />  
          
    <item android:state_pressed="true" 
        android:drawable="@drawable/jetpack_pressed" />  
          
</selector> 

    
[3] Dialog舒卷动画效果
    来源: 互联网  发布时间: 2014-02-18
Dialog伸缩动画效果

ViewScale.java:
Java代码 
public class ViewScale extends Activity implements OnClickListener {  
 
    private LinearLayout mLayout;  
    private Animation mScaleIn, mScaleOut;  
 
    @Override 
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
        mScaleIn = AnimationUtils.loadAnimation(this, R.anim.scale_in);  
        mScaleOut = AnimationUtils.loadAnimation(this, R.anim.scale_out);  
        mLayout = (LinearLayout) findViewById(R.id.mLayout);  
        Button btn = (Button) findViewById(R.id.btn);  
        btn.setOnClickListener(this);  
 
        iv = new ImageView(ViewScale.this);  
        LinearLayout.LayoutParams mParam = new LinearLayout.LayoutParams(  
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);  
        iv.setLayoutParams(mParam);  
        iv.setBackgroundResource(R.drawable.belle_frame);  
    }  
 
    private int i = 0;  
    private ImageView iv;  
 
    @Override 
    public void onClick(View v) {  
        if (i % 2 == 0) {  
            mLayout.addView(iv);  
            iv.startAnimation(mScaleOut);  
            mScaleOut.setAnimationListener(new AnimationListener() {  
                @Override 
                public void onAnimationStart(Animation animation) {  
                    // TODO Auto-generated method stub  
 
                }  
 
                @Override 
                public void onAnimationEnd(Animation animation) {  
                    // TODO Auto-generated method stub  
                    // mLayout.removeView(iv);  
                }  
 
                @Override 
                public void onAnimationRepeat(Animation animation) {  
                    // TODO Auto-generated method stub  
 
                }  
            });  
        } else {  
            iv.startAnimation(mScaleIn);  
            mScaleIn.setAnimationListener(new AnimationListener() {  
                @Override 
                public void onAnimationStart(Animation animation) {  
                    // TODO Auto-generated method stub  
 
                }  
 
                @Override 
                public void onAnimationEnd(Animation animation) {  
                    // TODO Auto-generated method stub  
                    mLayout.removeView(iv);  
                }  
 
                @Override 
                public void onAnimationRepeat(Animation animation) {  
                    // TODO Auto-generated method stub  
 
                }  
            });  
        }  
        i++;  
 
    }  
 


public class ViewScale extends Activity implements OnClickListener {

private LinearLayout mLayout;
private Animation mScaleIn, mScaleOut;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mScaleIn = AnimationUtils.loadAnimation(this, R.anim.scale_in);
mScaleOut = AnimationUtils.loadAnimation(this, R.anim.scale_out);
mLayout = (LinearLayout) findViewById(R.id.mLayout);
Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(this);

iv = new ImageView(ViewScale.this);
LinearLayout.LayoutParams mParam = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
iv.setLayoutParams(mParam);
iv.setBackgroundResource(R.drawable.belle_frame);
}

private int i = 0;
private ImageView iv;

@Override
public void onClick(View v) {
if (i % 2 == 0) {
mLayout.addView(iv);
iv.startAnimation(mScaleOut);
mScaleOut.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
// mLayout.removeView(iv);
}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}
});
} else {
iv.startAnimation(mScaleIn);
mScaleIn.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
mLayout.removeView(iv);
}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}
});
}
i++;

}

}



scale_out.xml:
Java代码 
<?xml version="1.0" encoding="utf-8"?>  
<set xmlns:android="http://schemas.android.com/apk/res/android">  
    <scale android:interpolator="@android:anim/accelerate_interpolator" 
        android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" 
        android:toYScale="1.0" android:pivotX="1%" android:pivotY="1%" 
        android:fillAfter="true" android:duration="400" />  
</set> 

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:interpolator="@android:anim/accelerate_interpolator"
android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0"
android:toYScale="1.0" android:pivotX="1%" android:pivotY="1%"
android:fillAfter="true" android:duration="400" />
</set>


scale_in.xml:
Java代码 
<?xml version="1.0" encoding="utf-8"?>  
<set xmlns:android="http://schemas.android.com/apk/res/android">  
    <scale android:interpolator="@android:anim/accelerate_interpolator" 
        android:fromXScale="1.0" android:toXScale="0.0" android:fromYScale="1.0" 
        android:toYScale="0.0" android:pivotX="1%" android:pivotY="1%" 
        android:fillAfter="true" android:duration="400" />  
</set> 

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android实现弹出键盘的方法 iis7站长之家
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3