Android项目开发实战常用知识点

Android项目开发实战常用知识点

一:启动页延时两秒再跳转到主界面:
//执行类
private class SlpashRunnable implements Runnable {
        @Override
        public void run() {
            Log.e("tag: ", "-----------------------");
             //判断是不是首次登录
            if (preferences.getBoolean("firstStart", true)) {

                SwitchAdTask switchAdTask = new SwitchAdTask(
                        SlpashActivity.this);
                switchAdTask.execute();             
            } else {
                jumpHome();
            }
        }
    }

//再onCreate方法中调用以下代码:
new Handler().postDelayed(new SlpashRunnable(), 2000);//延时两秒执行SlpashRunnable类


二:用SharedPreferences判断应用是否第一次登陆:
public class MainActivity extends Activity {

    private SharedPreferences spf;
    private Boolean b;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        spf = getSharedPreferences(Common.PACKANG_NAME, MODE_PRIVATE);
        b = spf.getBoolean("firstStart", true);
        if(b){
            //第一次登陆
            Log.e("tag: ", "first");
            spf.edit().putBoolean("firstStart", false).commit();
        }else{
            //二次以上登陆
            Log.e("tag: ", "second+");
        }
    }   
}


三:TextView选中变色
1:在color文件夹里新建selector文件,这里取名text_tab_background.xml

2:设置selector资源文件:
<?xml version="1.0" encoding="utf-8" ?>  
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:color="#C32F30" /><!-- 选择时的颜色 -->
    <item android:state_focused="true" android:color="#00FFFF" /><!-- 获得焦点是颜色 -->
    <item android:state_pressed="true" android:color="#FFff00" /><!-- 点击是的颜色 -->
    <item android:color="#a0a0a2"/><!-- 默认时的颜色 -->
</selector>

3:定义组件
<TextView
        android:id="@+id/tv_tab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:layout_marginBottom="3dp"
        android:singleLine="true"
        android:textColor="@color/text_tab_background"//在此次设置
        android:textSize="13sp" />


四:Button设置变色:
1:在drawable文件夹里新建selector文件,这里取名item_select.xml

2:分别制造两张同等类型不同颜色的九妹.9.png背景图

3:设置selector资源文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/z_2" //背景图的android:state_pressed="true"/>
    <item android:drawable="@drawable/z_1"
    android:state_focused="false" android:state_pressed="false"/>
    <item android:drawable="@drawable/z_2" android:state_focused="true"/>
    <item android:drawable="@drawable/z_1" android:state_focused="false"/>

</selector>

4:定义组件:
    <Button
        android:id="@+id/but"
        android:layout_width="80dp"
        android:layout_height="40dp"
        android:text="点击变色" 
        android:background="@drawable/item_select"/>


 五:未ImageView设置旋转动画(循环旋转):
 1:在res/anim文件夹下新建rotate旋转动画文件,share_anim.xml
 <?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromDegrees="0"
    android:interpolator="@android:anim/linear_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:toDegrees="+360" />

 2:设置布局:
 <ImageView
     android:id="@+id/shareImage"
     android:pivotX="50%"  
     android:pivotY="50%" 
     android:layout_width="47dp"
     android:layout_height="47dp"
     android:layout_gravity="center_vertical"
     android:src="@drawable/sy_tb_4" />

3:在Activity文件中绑定动画:
setRotate(this,shareImage);//为分享图片设置动画
    /**
     * 旋转动画
     * @param mcontext
     */
    public void setRotate(Context mcontext,ImageView image){
        Animation anim = AnimationUtils.loadAnimation(mcontext,
                R.anim.share_anim);
        LinearInterpolator lir = new LinearInterpolator();
        anim.setInterpolator(lir);
        image.startAnimation(anim);
    }


六:字符串:

6.1字符串格式化:
String toast = String.format("%s%d", "您的当前总积分为:", allScore);//%s代表字符串;%d代表整形,意思是将前半部分转换为String,allScore转换为整形


七:设置控件的隐藏,显示,不可见和不可点击等状态

android:visibility="visible"  //控件正常显示
android:visibility="invisible" //不可见
android:visibility="gone"//隐藏
android:enabled="false"//不响应操作,颜色为灰色
android:editable="false"//编辑款不可编辑
android:ems="10"//设置控件长点为10个单位,超出部分不再显示
android:ellipsize="none"//设置为单行显示


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值