模板
模板更新中········
String value1,value2
String url = "";
OkHttpClient okHttpClient = new OkHttpClient();
RequestBody formBody = new FormBody.Builder()//填充数据
.add("key1", value1)
.add("key2", value1)
.build();
final Request request = new Request.Builder()
.url(url)
.post(formBody)
.build();
Call call = okHttpClient.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("error", "onFailure: ", e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.i("info", "onResponse: " + response.body().string());
}
});
AlertDialog alertDialog = new AlertDialog.Builder(v.getContext()).create();
alertDialog.setTitle("");
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.setMessage("");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "退", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
//alertDialog0.setCanceledOnTouchOutside(false); //此行可以让警告框的外部区域不可触摸
alertDialog.show();
Toast.makeText(this,“内容”,Toast.LENGTH_SHORT).show();
有的时候会报错,使用下面的代码: Looper.prepare(); Toast.makeText(getApplicationContext(),“内容”,Toast.LENGTH_SHORT); Looper.loop();
方式一:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0) ;
方式二(推荐):
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if(imm != null) {
imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(),0);
}
//修改字体
Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/ziti.ttf");
// 应用字体
textView.setTypeface(typeFace);
public void setToolbar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle("");
}
SharedPreferences sp = getSharedPreferences("base", MODE_PRIVATE);
string=sp.getString( , )
SharedPreferences.Editor editor = getSharedPreferences("base", MODE_PRIVATE).edit();
editor.putString();
editor.commit();
class StudyWordAdapter extends PagerAdapter {
public List<View> list_view;
private TextView word, translate;
@Override
public int getCount() {
return list_view.size();
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
container.addView(list_view.get(position));
return list_view.get(position);
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View)object);
}
@Override
public int getItemPosition(Object object)
{
return null!=list_view&& list_view.size()==0?POSITION_NONE:super.getItemPosition(object);
}
}
Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
Bundle data = msg.getData();
return false;
}
});
Runnable networkTask = new Runnable() {
@Override
public void run() {
// TODO
// 在这里进行 http request.网络请求相关操作
Message msg = new Message();
Bundle data = new Bundle();
msg.setData(data);
handler.sendMessage(msg);
}
};
new Thread(networkTask).start();
//第一个参数我设置的是TextView,根据需要改变。
public void setAnimation(TextView textView,int b) {
//动画
ValueAnimator anim = ValueAnimator.ofInt(0, 360);
anim.setDuration(250);//持续时间
anim.setRepeatCount(0);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int currentValue = (Integer) animation.getAnimatedValue();
// 获得改变后的值
((ConstraintLayout.LayoutParams)textView.getLayoutParams()). = currentValue;
}
});
anim.start();
}