Lazytool

本文介绍了一个简单的安卓程序,用于解决使用手机词典时屏幕自动变暗并锁定的问题。通过获取屏幕唤醒锁,设置活动背景颜色及按钮背景等方式,确保用户查词时屏幕保持亮起状态。

In case that  when I  was using the dictionary on mobile, the screen darkens and later locked unless we kept on touching it . It is really strange that why the dictionary providers forget about it, since we all know the mobie is  very frequently used when we are studying English or doing sth else.

So, I wrote an android program here to solve the issue. The code is simple , here are some notes:

1. How to get the wakelock?

mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, getClass().getName());

2. How to set the backgroud color of the actvity?

        ll = (LinearLayout)findViewById(R.id.root);
        ll.setBackgroundColor(Color.BLACK);

3. How to change the background of the imagebutton?

        Resources rs = getBaseContext().getResources();
        if ("ON".equals(mState))
        {
            Drawable da = rs.getDrawable(R.drawable.turnon);
            mImageButton.setBackground(da);
        }
        else
        {
            Drawable da = rs.getDrawable(R.drawable.turnoff);
            mImageButton.setBackground(da);
        }

4. How to place the picture in the center of the screen?

<LinearLayout 
.....
    android:gravity="center_vertical"
    android:id="@+id/root"
.....  
/>

<ImageButton
.....
            android:layout_gravity="center|center_vertical"
....
/>

 Screenshots

  

2013-08-10

转载于:https://www.cnblogs.com/getout/p/3249859.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值