Android总结【不定期更新】
全屏显示:
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
继承Activity下取消标题栏:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
继承AppCompatActivity下取消标题栏:
this.getSupportActionBar().hide();
隐藏导航栏
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View decorView = getWindow().getDecorView();
int option = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(option);
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
透明状态栏(内容填充至状态栏下部)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//平台版本需大于等于android 5.0
if (Build.VERSION.SDK_INT >= 21) {
View decorView = getWindow().getDecorView();
int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(option);
//设置状态栏透明
getWindow().setStatusBarColor(Color.TRANSPARENT);
}
ActionBar actionBar = getSupportActionBar();
//隐藏标题栏
actionBar.hide();
该条引自郭神大佬!!!:https://blog.csdn.net/guolin_blog/article/details/51763825
感谢大佬:https://www.cnblogs.com/xiangevan/p/7818159.html
Android动态设置TextView的颜色的四种方法
package com.txlong;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;
public class ListViewDemoActivity extends Activity {
// private ListView listView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Test set TextView's color.");
//方案一:通过ARGB值的方式
/**
* set the TextView color as the 0~255's ARGB,These component values
* should be [0..255], but there is no range check performed, so if they
* are out of range, the returned color is undefined
*/
// tv.setTextColor(Color.rgb(255, 255, 255));
/**
* set the TextView color as the #RRGGBB #AARRGGBB 'red', 'blue',
* 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow',
* 'lightgray', 'darkgray'
*/
tv.setTextColor(Color.parseColor("#FFFFFF"));
/** 原来不知道有上边的方法,就用这个笨笨方法了 */
// String StrColor = null;
// StrColor = "FFFFFFFF";
// int length = StrColor.length();
// if (length == 6) {
// tv.setTextColor(Color.rgb(
// Integer.valueOf(StrColor.substring(0, 2), 16),
// Integer.valueOf(StrColor.substring(2, 4), 16),
// Integer.valueOf(StrColor.substring(4, 6), 16)));
// } else if (length == 8) {
// tv.setTextColor(Color.argb(
// Integer.valueOf(StrColor.substring(0, 2), 16),
// Integer.valueOf(StrColor.substring(2, 4), 16),
// Integer.valueOf(StrColor.substring(4, 6), 16),
// Integer.valueOf(StrColor.substring(6, 8), 16)));
// }
//方案二:通过资源引用
// tv.setTextColor(getResources().getColor(R.color.my_color));
//方案三:通过资源文件写在String.xml中
// Resources resource = (Resources) getBaseContext().getResources();
// ColorStateList csl = (ColorStateList) resource.getColorStateList(R.color.my_color);
// if (csl != null) {
// tv.setTextColor(csl);
// }
//方案四:通过xml文件,如/res/text_color.xml
// XmlPullParser xrp = getResources().getXml(R.color.text_color);
// try {
// ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);
// tv.setTextColor(csl);
// } catch (Exception e) {
// }
// listView = new ListView(this);
//
// Cursor cursor = getContentResolver().query(
// Uri.parse("content://contacts/people"), null, null, null, null);
//
// startManagingCursor(cursor);
//
// ListAdapter listAdapter = new SimpleCursorAdapter(this,
// android.R.layout.simple_expandable_list_item_2, cursor,
// new String[] { "name", "name" }, new int[] {
// android.R.id.text1, android.R.id.text2 });
//
// listView.setAdapter(listAdapter);
// setContentView(listView);
setContentView(tv);
}
}
感谢大佬:https://blog.csdn.net/liuming_nx/article/details/17583905
View.setBackgroundColor(Color.BLUE); //背景颜色设置为 Blue
View.setBackgroundResource(0)//移除背景,包括:背景颜色,图片等等
感谢大佬:https://blog.csdn.net/gf771115/article/details/8230176
Android中dip(dp)与px之间单位转换
/**
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)
*/
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
/**
* 根据手机的分辨率从 px(像素) 的单位 转成为 dp
*/
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}
注:后面的0.5f是因为转int类型还要四舍五入,为保证精准度。
android 判断edittext是否为空
感谢大佬:
Android中EditText就是文本输入控件,它的值是个String类型,
判断输入是否为空可以通过String TextUtil 等API来判断
有以下几种方式:https://zhidao.baidu.com/question/710806300136762005.html
直接判断EditText的长度editText.length() 如果等于0则为空
通过TextUtil.isEmpty(editText.getText()) true表示是空,false表示非空
通过正则表达式
通过String.length() 判断长度
以下为示例代码,如果为空,则跳出提示:
String txt = editText.getText().toString();
if(txt.length() == 0){
Toast.makeText(context,"输入不能为空",0).show(); //弹出一个自动消失的提示框
return;
}
补充:占位符 %1$s %1$d
感谢大佬:https://blog.csdn.net/jiangtea/article/details/71156047
%n$ms:代表输出的是字符串,n代表是第几个参数,设置m的值可以在输出之前放置空格
%n$md:代表输出的是整数,n代表是第几个参数,设置m的值可以在输出之前放置空格,也可以设为0m,在输出之前放置m个0
%n$mf:代表输出的是浮点数,n代表是第几个参数,设置m的值可以控制小数位数,如m=2.2时,输出格式为00.00
在string.xml中
<string name="alert">我的名字叫%1$s,我来自%2$s,我今年%3$d岁了</string>
代码
String string= getResources().getString(R.string.alert);
tv.setText(String.format(string, "隔壁老汪","上海",30));

补充:注意符号问题!!!
Android总结【不定期更新】的更多相关文章
- 基于C/S架构的3D对战网络游戏C++框架_【不定期更新通知】
由于笔者最近有比赛项目要赶,这个基于C/S架构的3D对战网络游戏C++框架也遇到了一点瓶颈需要点时间沉淀,所以近一段时间不能保证每天更新了,会保持不定期更新.同时近期笔者也会多分享一些已经做过学过的C ...
- 解决Android SDK Manager更新、下载速度慢
hosts文件里面原来的内容不做修改,只是添加内容 方法/步骤 先看看如何加快更新速度,再说如何更新. 首先更新host文件,如图,打开目录 C:\Windows\System32\drivers\e ...
- Android中动态更新ListView(转)
在使用ListView时,会遇到当ListView列表滑动到最底端时,添加新的列表项的问题,本文通过代码演示如何动态的添加新的列表项到ListView中.实现步骤:调用ListView的setOnSc ...
- Android Studio 解决更新慢的问题
Android Studio 解决更新慢的问题 最近在一些群里有伙伴们反应工具更新慢,由于国内网络对google限制的原因,android studio更新一直是个老大难的问题,为了,提高sdk下载的 ...
- Android Studio安装更新终极解决方式
之前写过一篇Android SDK无法更新的博文,其实该方式对Android Studio同样有效,大伙可以下载网盘中分享的小软件,若搜索到通道后提示需要更细,也可以选择更新.参考:http://bl ...
- 如何处理Android SDK无法更新问题?
在Android开发中,最痛苦的事情就是相关库升级后,Android SDK太低,跑步起来,最最痛苦的事情就是,想更新,却因大天朝的一墙之隔,愣是没法更新.遇到这种情况怎么办呢?小编和大家分享一个解决 ...
- Android SDK无法更新问题解决 ---- 还可解决无法上google的问题
Android SDK无法更新问题解决 2012-10-14 10:13:01| 分类: Android|举报|字号 订阅 1.在SDK Manager下Tools->Options打 ...
- Android SDK Manager 更新失败的解决方法
Android SDK Manager 更新失败的解决方法 原文地址 最近使用Android SDK Manager 更新Android SDK tools 发现经常更新失败,获取不到更新信息: Fe ...
- Android SDK Manager更新不了的解决办法
android SDK Manager更新不了,出现错误提示:"Failed to fetch URL..."! 可以用以下办法解决: 使用SDK Manager更新时出现问题 F ...
- android studio无法更新之解决方案
当发现android studio有更新时,当然第一时间就想更新,可惜被墙了. 解决方案: 下载wallproxy,百度你懂的 在proxy.ini中最上面,找到ip和port 接着,在android ...
随机推荐
- MQ消费失败,自动重试思路
在遇到与第三方系统做对接时,MQ无疑是非常好的解决方案(解耦.异步).但是如果引入MQ组件,随之要考虑的问题就变多了,如何保证MQ消息能够正常被业务消费.所以引入MQ消费失败情况下,自动重试功能是非常 ...
- MySQL高级查询与编程笔记 • 【第4章 MySQL编程】
全部章节 >>>> 本章目录 4.1 用户自定义变量 4.1.1 用户会话变量 4.1.2 用户会话变量赋值 4.1.3 重置命令结束标记 4.1.4 实践练习 4.2 存 ...
- 【MySQL作业】多字段分组和 having 子句——美和易思分组查询应用习题
点击打开所使用到的数据库>>> 1.按照商品类型和销售地区分组统计商品数量和平均单价,并按平均单价升序显示. -- 按照商品类型和销售地区分组统计商品数量和平均单价,并按平均单价升序 ...
- 对接网易云信音视频2.0呼叫组件集成到vue中,实现web端呼叫app,视频语音通话。
项目中需要实现视频通话功能,经过公司的赛选,采用网易云信的视频通话服务,app小伙伴集成很顺利.web端需要实现呼叫app端用户.网易云信文档介绍不全,vue的demo满足不了需求,和客服人员沟通,只 ...
- x86-2-保护模式(protect mode)
x86-2-保护模式(protect mode) 引入保护模式的原因: 操作系统负责计算机上的所有软件和硬件的管理,它可以百分百操作计算机的所有内容.但是,操作系统上编写的用户程序却应当有所限制,比如 ...
- MongoDB应用场景及选型
1. MongoDB数据库定位 * OLTP数据库 * 原则上Oracle和MySQL能做得事情,MongoDB都能做(包括ACID事务) * 优点:横向扩展能力,数据量或并发量增加时候可以自动扩展 ...
- xorm 条件查询时区的问题
问题描述:如果在查询的时候,直接传时间格式作为条件,时间会被驱动程序转为UTC格式,因此会有8个小时的误差. 解决方案1: 将查询时间转为字符串 db.where("time > ?& ...
- Microsoft HoloLens 开发(3): 全息图交互方式 - Gaze
Gaze(凝视) 是 HoloLens 交互输入的第一种形式,告诉你 用户 在世界上的位置,并让你确定他们的意图. 1.Gaze的用途 作为一个 Mixed Reality 开发者,Gaze 可以做很 ...
- 深入了解mysql--gap locks,Next-Key Locks
Next-Key Locks Next-Key Locks是在存储引擎innodb.事务级别在可重复读的情况下使用的数据库锁,官网上有介绍,Next-Key Locks是行锁和gap锁的组合.行锁是什 ...
- 接口神器之 Json Server 详细指南
简介 json-server 是一款小巧的接口模拟工具,一分钟内就能搭建一套 Restful 风格的 api,尤其适合前端接口测试使用. 只需指定一个 json 文件作为 api 的数据源即可,使用起 ...