个人需要记住的

1.动态设置textView颜色
去res下的color.xml里添加,列入:


    #008577
    #00574B
    #D81B60
    #00ff00

在活动中通过:

  textView.setBackgroundResource(R.color.sb);

2.点击电话号跳转到拨打页面

ntent dialIntent =  new Intent(Intent.ACTION_CALL,Uri.parse("tel:" + phoneNumber));//直接拨打电话
 startActivity(dialIntent);
 Intent dialIntent =  new Intent(Intent.ACTION_CALL_BUTTON);//跳转到拨号界面
 startActivity(dialIntent);
 Intent dialIntent =  new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" + phoneNumber));//跳转到拨号界面,同时传递电话号码

3.EditText

android:singgleline:"false"//实现单行输入
aandroid:maxlines:"1"//实现输入行数
Android:inputType:"textvisiblepassword"//显示输出内容
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"//则无论手机如何变动,拥有这个属性的activity都将是竖屏显示。
android:screenOrientation="landscape"//为横屏显示

4.隐藏ActionBar

 ActionBar actionBar=getSupportActionBar();
        if (actionBar!=null){
            actionBar.hide();
        }

4.list集合排序
在自己需要关联的类里实现:

public class People implements Comparable {
*/需要的属性
*/
  @Override
    public int compareTo(People people) {
        int i=this.getId()-people.getId();
        return i;
    }
}

我们会发现sort(List)方法中List中的T必须实现Comparable接口,然后实现 compareTo()方法,该方法的返回值0代表相等,1表示大于,-1表示小于;
在acyivity中加入:

private List list=new ArrayList<>();
 list.add(new People(5,"上海",23));
        list.add(new People(4,"武汉",20));
        list.add(new People(3,"武汉",50));
        Collections.sort(list);

第二种:

private List list=new ArrayList<>();
       list.add(new People(5,"上海",23));
        list.add(new People(4,"武汉",20));
        list.add(new People(3,"武汉",50));
        Collections.sort(list, new Comparator() {
            @Override
            public int compare(People people, People t1) {
                int i=people.getId()-t1.getId();
                return i;
            }
        });

5.SharedPreferences
存入数据:

 SharedPreferences users=getSharedPreferences("data",0);//第一个参数是文件名,第二个参数是只有当前的应用程序才可以对这个文件进行读写
        SharedPreferences.Editor editor=users.edit();//添加数据
        editor.putString("name","www");
        editor.putString("URL","www.baidu");
        editor.apply();//提交

读取数据:

 SharedPreferences users=getSharedPreferences("data",0);
        String name=users.getString("name","");
        String url=users.getString("URL","");
        Log.d("Main15Activity", "数据:"+name);
        Log.d("Main15Activity", "网址:"+url);

表格画线
首先在res下的drawable建立两个xml文件:
ic_shape_line.xml竖线


    
    

ic_shape_row.xml横线


     
    

 
        
            
            
            
        
    

圆形图片:

 

给Textview加圆形边框:首先在res下的drawable里面建立一个xml布局文件如下内容
acc.xml


    
    
    

给TextView加矩形边框步骤同上,内容如下:
border.xml


    

    

    
    


9.根据url渲染Imageview:

imageView=findViewById(R.id.image1);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    URL picurl=new URL("http://pic3.nipic.com/20090520/2489240_222607039_2.jpg");
                    final Bitmap pngBM= BitmapFactory.decodeStream(picurl.openStream());
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            imageView.setImageBitmap(pngBM);
                        }
                    });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();

工具类

private Bitmap utile(String uri){
        Bitmap bitmap=null;
        try {
            bitmap=BitmapFactory.decodeStream(new URL(uri).openStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return  bitmap ;
    }

Textview跑马灯

android:singleLine="true" //单行显示
android:ellipsize="marquee" //跑马灯显示(动画横向移动)
android:marqueeRepeatLimit="marquee_forever"//永久滚动
android:focusable="true" //控件是否能够获取焦点
android:focusableInTouchMode="true" //是否在触摸模式下获得焦点

11.动态改变Button颜色

btn_signed.setBackgroundColor(Color.parseColor("#7CFC00"));

12.定时器

 new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                CommonUtil.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        textView.setText(i+"");
                    }
                });
                i++;
            }
        },5000,2000);

13.活动传值

 Intent intent=new Intent(TextActivity.this,PracticeActivity.class);
                intent.putExtra("data",num);
                startActivity(intent);
  Intent intent=getIntent();
                String name= intent.getStringExtra("data");
                textView.setText(name);
  handler.postDelayed(runnable,3000);
    }
    private Handler handler=new Handler(){
        @Override
        public String getMessageName(Message message) {
            return super.getMessageName(message);
        }
    };
     Runnable runnable=new Runnable() {
        @Override
        public void run() {
            Intent intent=new Intent(SplashActivity.this,MainActivity.class);
            startActivity(intent);
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacks(runnable);
    }

13.记住密码

 private SharedPreferences sharedPreferences;
     private SharedPreferences.Editor editor;
     private EditText editTextname,editTextpassword;
     private CheckBox checkBoxpw,checkBoxauto;
     private Button buttonlogin;
    private String userNameValue,passwordValue;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_testlogin);
        sharedPreferences=this.getSharedPreferences("data",0);
        editTextname=findViewById(R.id.et_zh);
        editTextpassword=findViewById(R.id.et_mima);
        checkBoxpw=findViewById(R.id.cb_mima);
        checkBoxauto=findViewById(R.id.cb_auto);
        buttonlogin=findViewById(R.id.btn_login);
        if (sharedPreferences.getBoolean("ISCHECK",false)){
            checkBoxpw.setChecked(true);
            editTextname.setText(sharedPreferences.getString("USERNAME",""));
            editTextpassword.setText(sharedPreferences.getString("PASSWORD",""));
            if (sharedPreferences.getBoolean("AUTO_ISCHECK",false)){
                checkBoxauto.setChecked(true);
                startActivity(new Intent(TestloginActivity.this, SplashActivity.class));
            }
        }
        buttonlogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                userNameValue=editTextname.getText().toString();
                passwordValue=editTextpassword.getText().toString();
                if (userNameValue.equals("wang")&&passwordValue.equals("123")){
                    Toast.makeText(TestloginActivity.this,"登陆成功",Toast.LENGTH_SHORT).show();
                    if (checkBoxpw.isChecked()){
                        editor=sharedPreferences.edit();
                         editor.putString("USERNAME",userNameValue);
                         editor.putString("PASSWORD",passwordValue);
                         editor.commit();
                    }
                    startActivity(new Intent(TestloginActivity.this,SplashActivity.class));
                }else {
                    Toast.makeText(TestloginActivity.this,"用户名或密码错误,请重新登录", Toast.LENGTH_LONG).show();
                }
            }
        });
        checkBoxpw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (checkBoxpw.isChecked()){
                    Toast.makeText(TestloginActivity.this,"记住密码已选中", Toast.LENGTH_SHORT).show();
                    sharedPreferences.edit().putBoolean("ISCHECK",true).commit();
                }else {
                    Toast.makeText(TestloginActivity.this,"记住密码没有选中", Toast.LENGTH_SHORT).show();
                    sharedPreferences.edit().putBoolean("ISCHECK",false).commit();
                }
            }
        });
        checkBoxauto.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (checkBoxauto.isChecked()){
                    Toast.makeText(TestloginActivity.this, "自动登录已选中", Toast.LENGTH_SHORT).show();
                   sharedPreferences.edit().putBoolean("AUTO_ISCHECK",true).commit();
//                   boolean t=sharedPreferences.getBoolean("AUTO_ISCHECK",false);
                }else {
                    Toast.makeText(TestloginActivity.this, "自动登录未选中", Toast.LENGTH_SHORT).show();
                     sharedPreferences.edit().putBoolean("AUTO_ISCHECK",false).commit();
                }
            }
        });
    }
  private SharedPreferences sharedPreferences;
     private SharedPreferences.Editor editor;
     private EditText editTextuser,editTextpassword;
     private CheckBox checkBoxpassword,checkBoxauto;
     private Button button;
     private String nameValue,passwordValue;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_testlogin);
        editTextuser=findViewById(R.id.user_name);
        editTextpassword=findViewById(R.id.user_password);
        checkBoxpassword=findViewById(R.id.check_password);
        checkBoxauto=findViewById(R.id.check_auto);
        button=findViewById(R.id.button_login);
        sharedPreferences=this.getSharedPreferences("data",0);
        if (sharedPreferences.getBoolean("ISCHECK",false)){
            checkBoxpassword.setChecked(true);
             editTextuser.setText(sharedPreferences.getString("USERNAME",""));
             editTextpassword.setText(sharedPreferences.getString("PASSWORD",""));
             if (sharedPreferences.getBoolean("AUTO_ISCHECK",false)){
                 checkBoxauto.setChecked(true);
                 startActivity(new Intent(TestloginActivity.this, WebviewActivity.class));
             }
        }
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                nameValue=editTextuser.getText().toString();
                passwordValue=editTextpassword.getText().toString();
                if (nameValue.equals("wang")&&passwordValue.equals("123")){
                    Toast.makeText(TestloginActivity.this,"登陆成功",Toast.LENGTH_SHORT).show();
                    if (checkBoxpassword.isChecked()){
                        editor=sharedPreferences.edit();
                        editor.putString("USERNAME",nameValue);
                        editor.putString("PASSWORD",passwordValue);
                        editor.commit();
                    }
                    startActivity(new Intent(TestloginActivity.this,WebviewActivity.class));
                }else {
                    Toast.makeText(TestloginActivity.this,"用户名或密码错误",Toast.LENGTH_SHORT).show();
                }
            }
        });
        checkBoxpassword.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (checkBoxpassword.isChecked()){
                    Toast.makeText(TestloginActivity.this,"记住密码已经被勾选",Toast.LENGTH_SHORT).show();
                    sharedPreferences.edit().putBoolean("ISCHECK",true).commit();
                }else {
                    Toast.makeText(TestloginActivity.this,"记住密码已经被勾选",Toast.LENGTH_SHORT).show();
                    sharedPreferences.edit().putBoolean("ISCHECK",true).commit();
                }
            }
        });
        checkBoxauto.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (checkBoxauto.isChecked()){
                    Toast.makeText(TestloginActivity.this,"自动登陆已经被勾选",Toast.LENGTH_SHORT).show();
                    sharedPreferences.edit().putBoolean("AUTO_ISCHECK",true).commit();
                }else {
                    Toast.makeText(TestloginActivity.this,"自动登陆已经被勾选",Toast.LENGTH_SHORT).show();
                    sharedPreferences.edit().putBoolean("AUTO_ISCHECK",false).commit();
                }
            }
        });
    }
}

一些小点

 
switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    //Todo
                    textView.setText("开");
                }else {
                    //Todo
                    textView.setText("关");
                }
            }
        });
 public void image1(View view) {
        if (m == 0) {
            linearLayout1.setVisibility(View.VISIBLE);
            linearLayout3.setVisibility(View.VISIBLE);
            imageView1.setRotation(90);//旋转
            m = 1;
        } else {
            linearLayout1.setVisibility(View.GONE);
            linearLayout3.setVisibility(View.GONE);
            imageView1.setRotation(0);
            m = 0;
        }

15,webview

下面是HTML5引用css文件:


Html5引用js文件


        WebSettings webSettings = webView.getSettings();
        // 设置与Js交互的权限
        webSettings.setJavaScriptEnabled(true);
        // 设置允许JS弹窗
       webSettings.setJavaScriptCanOpenWindowsAutomatically(true);

你可能感兴趣的:(个人需要记住的)