Android+java程序开发笔记|持续更新

//关闭标题栏 android:theme="@style/Theme.AppCompat.Light.NoActionBar">

 //获取文字id状态
TextView lblTitle=(TextView)findViewById(R.id.a1);
//获取文本信息
String name=liblTitle.getText().toString();
//修改文字内容
lblTitle.setText("这是显示的内容");
 
 
//获取图片id状态
ImageView b=(ImageView)findViewById((R.id.a2));
//修改图片
b.setImageDrawable(getDrawable(R.drawable.huanqi)); 
//跳转界面 
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent); 
//隐式跳转 
Intent intent=new Intent("android.intent.action.MY"); 
startActivity(intent); 
//选择性隐式跳转
Intent intent=new Intent("android.intent.action.MY"); 
intent.setAction(Intent.ACTION_VIEW); 
intent.setData(Uri.parse("https://www.baidu.com")); 
startActivity(intent); 
manifests界面添加内容: 
<activity android:name=".MainActivity2"> 
<intent-filter> 
<action android:name="android.intent.action.MY"/> 
<category android:name="android.intent.category.DEFAULT"/> </intent-filter> 
</activity> 

//等待3秒跳转界面 
final Intent intent = new Intent(MainActivity.this, Main2Activity.class); 
Timer timer = new Timer(); 
TimerTask task = new TimerTask() 
{     
@Override public void run() 
{         
startActivity(intent);     
} 
}; 
timer.schedule(task, 3000); 
//跳转后结束当前界面 finish();     
//提示 Toast toast= Toast.makeText(getApplicationContext(),"哈哈", Toast.LENGTH_SHORT);       
toast.show(); 
//判断 当dlzh1等于25时执行 
if (dlzh1.equals("25")) 
{
} 
DriverManager类:依据数据库的不同管理jdbc驱动       
Connection接口:负责连接数据库并担任传送数据的任务。       
Statement 接口:友Connection产生,负责执行sql语句。       
ResultSet接口:负责保存Statement执行后所产生的查询结果。 
//隐藏标题栏状态栏 requestWindowFeature(Window.FEATURE_NO_TITLE);
//隐藏标题栏 
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
//隐藏状态栏 //放在setContentView(R.layout.activity_main3);前面 //限制输入内容只能为:
android:digits="0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM" 
//布局显示
Visibility final TextView textView2= (TextView)findViewById(R.id.text2); 
int a=textView2.getVisibility(); 
if (a==8) 
{ 
textView2.setVisibility(View.VISIBLE); 
} 
else 
{ 
textView2.setVisibility(View.GONE); 
} 权限 
//因特网 
<uses-permission android:name="android.permission.INTERNET" /> 
//移动数据 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
//WIFI数据 
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
//修改控件长度
ViewGroup.LayoutParams layoutParams=linearLayout.getLayoutParams();
layoutParams.width=100;
linearLayout.setLayoutParams(layoutParams);

//滑动窗体
滑动窗体使用控件:<androidx.viewpager.widget.ViewPager>
 ViewPager viewPager = findViewById(R.id.hd);
 List<View> views = new ArrayList<View>();
 LayoutInflater layoutInflater = LayoutInflater.from(getApplicationContext());

 View view1 = layoutInflater.inflate(R.layout.activity_main2,null);
 View view2 = layoutInflater.inflate(R.layout.activity_main3,null);
 views.add(view1);
 views.add(view2);

//执行GuidPageAdapter.java中的方法
GuidPageAdapter guidPageAdapter = new GuidPageAdapter(views);
 viewPager.setAdapter(guidPageAdapter);
//对指定控件进行操作时添加view1
TextView textView= (TextView)view1.findViewById(R.id.text1);
----------------java文件分解线-------------------

//GuidPageAdapter.java文件内容
package com.android.huadong;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import java.util.List;
public class GuidPageAdapter extends PagerAdapter {
    List<View> views;
    public  GuidPageAdapter(List<View> views) {
        this.views = views;
    }
    @Override
    //获取当前窗体界面数
    public int getCount() {
        return views.size();
    }
    @Override
    //判断是否由对象生成界面
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }
    @Override
    //使从ViewGroup中移出当前View
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        ((ViewPager)container).removeView(views.get(position));
    }
    @NonNull
    @Override
    //返回一个对象,这个对象表明了PagerAdapter适配器选择哪个对象放在当前的ViewPager中
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        ((ViewPager)container).addView(views.get(position));
        return views.get(position);
    }
}

java分区————————java分区

//线程 t.start()是执行此线程
Thread t = new Thread(new Runnable(){
    public void run(){
      
    }});
t.start();
//获取线程名称
String name = Thread.currentThread().getName();

3 Replies to “Android+java程序开发笔记|持续更新”

发表评论

邮箱地址不会被公开。 必填项已用*标注