全屏显示:

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总结【不定期更新】的更多相关文章

  1. 基于C/S架构的3D对战网络游戏C++框架 _【不定期更新通知】

    由于笔者最近有比赛项目要赶,这个基于C/S架构的3D对战网络游戏C++框架也遇到了一点瓶颈需要点时间沉淀,所以近一段时间不能保证每天更新了,会保持不定期更新.同时近期笔者也会多分享一些已经做过学过的C ...

  2. 解决Android SDK Manager更新、下载速度慢

    hosts文件里面原来的内容不做修改,只是添加内容 方法/步骤 先看看如何加快更新速度,再说如何更新. 首先更新host文件,如图,打开目录 C:\Windows\System32\drivers\e ...

  3. Android中动态更新ListView(转)

    在使用ListView时,会遇到当ListView列表滑动到最底端时,添加新的列表项的问题,本文通过代码演示如何动态的添加新的列表项到ListView中.实现步骤:调用ListView的setOnSc ...

  4. Android Studio 解决更新慢的问题

    Android Studio 解决更新慢的问题 最近在一些群里有伙伴们反应工具更新慢,由于国内网络对google限制的原因,android studio更新一直是个老大难的问题,为了,提高sdk下载的 ...

  5. Android Studio安装更新终极解决方式

    之前写过一篇Android SDK无法更新的博文,其实该方式对Android Studio同样有效,大伙可以下载网盘中分享的小软件,若搜索到通道后提示需要更细,也可以选择更新.参考:http://bl ...

  6. 如何处理Android SDK无法更新问题?

    在Android开发中,最痛苦的事情就是相关库升级后,Android SDK太低,跑步起来,最最痛苦的事情就是,想更新,却因大天朝的一墙之隔,愣是没法更新.遇到这种情况怎么办呢?小编和大家分享一个解决 ...

  7. Android SDK无法更新问题解决 ---- 还可解决无法上google的问题

    Android SDK无法更新问题解决 2012-10-14 10:13:01|  分类: Android|举报|字号 订阅     1.在SDK Manager下Tools->Options打 ...

  8. Android SDK Manager 更新失败的解决方法

    Android SDK Manager 更新失败的解决方法 原文地址 最近使用Android SDK Manager 更新Android SDK tools 发现经常更新失败,获取不到更新信息: Fe ...

  9. Android SDK Manager更新不了的解决办法

    android SDK Manager更新不了,出现错误提示:"Failed to fetch URL..."! 可以用以下办法解决: 使用SDK Manager更新时出现问题 F ...

  10. android studio无法更新之解决方案

    当发现android studio有更新时,当然第一时间就想更新,可惜被墙了. 解决方案: 下载wallproxy,百度你懂的 在proxy.ini中最上面,找到ip和port 接着,在android ...

随机推荐

  1. 昆泰CH7511B方案|EDP转LVDS资料|CS5211pin to pin 替代CH7511B电路设计

    Chrontel的CH7511B是一种低成本.低功耗的半导体器件,它将嵌入式DisplayPort信号转换为LVDS(低压差分信号).这款创新的DisplayPort接收机带有集成LVDS发射机,专为 ...

  2. 生成器执行函数co 源码解读

    本文所选内容均来自[co模块源码] /** * slice() reference. */ var slice = Array.prototype.slice; module.exports = co ...

  3. Java基础寒假作业-简易计算器

    需求: 使用Java编写计算器的控制台程序,完成简单的加减乘除运算.实现以下功能: 1.运算选择 请用户选择一个算法(1.加法 2.减法 3.乘法 4.除法 5.关闭计算器) 2.计算 a)加法:实现 ...

  4. Docker | dockerfile 文件编写

    dockerfile 的作用 dockerfile 作用就是制作镜像,保持开发,测试,生产环境的一致性. 直接将容器制作为镜像 制作新的镜像 # 把容器按照自己的需求个性完之后,就可以创建自己的镜像的 ...

  5. Ranger架构剖析

    Ranger介绍 2016年,Hadoop迎来了自己十周岁生日.过去的十年,Hadoop雄霸武林盟主之位,号令天下,引领大数据技术生态不断发展壮大,一时间百家争鸣,百花齐放.然而,兄弟多了不好管,为了 ...

  6. CSS基础 阴影相关属性设置

    一.字体阴影属性名:text-shadow:水平偏移量 垂直偏移量 模糊度 阴影颜色: html代码: <div>农夫山泉有点甜</div>css代码: div{ font-s ...

  7. CSS基础 CSS的三大特性以及选择器优先级计算方法

    1.子元素默认会继承父元素的样式,但不是所有的元素都有继承 常见的继承父元素特点的元素有: 1.color 2.font-sytle.font-weight.font-size.font-family ...

  8. oracle 之 while循环月份

    需求 需要跑一个数据,时间从17年5月到21年3月. 代码(简单粗暴实现) DECLARE i number; BEGIN i:= 201705; WHILE i <202104 LOOP if ...

  9. 基于CentOS6.5-Hadoop2.7.3-hive-2.1.1安装sqoop1.4.7

    注:图片如果损坏,点击文章链接:https://www.toutiao.com/i6627736198431375879/ 系统版本,Hadoop已安装完成.链接<CentOS6.5下安装Had ...

  10. PPT制作手机滑动粗糙效果

    原文链接:https://www.toutiao.com/i6495291974680052238/ 选择"插入"选项卡,"插图"功能组."形状&qu ...