getFragmentManager()被弃用的代替方法
getFragmentManager()被弃用的代替方法 当需要管理activity或者fragment中的fragment时使用getChildFragmentManager()。 当需要本身需要与fragment关联的activity交互时使用getParentFragmentManager()。 以下为getParentFragment()方法的注释: Return the FragmentManager for interacting with fragments associated with this fragment’s activity. Note that this will be available slightly before getActivity(), during the time from when the fragment is placed in a FragmentTransaction until it is committed and attached to its activity.If this Fragment is a chil...
Android Crash问题
Android在API21(Android5.0)以下,crash后会直接退出整个应用,但是在API21(Android5.0)以上系统时,会遵循以下原则重启: 包含service:如果程序crash的时候运行着service,那么系统会重新启动service。 不包含service,但是当前栈中包含两个Activity,A->B,如果B crash,那么系统会重启A。 不包含service,但是当前栈中包含三个Activity,A->B->C,如果C crash,那么系统会重启B,并且A仍然存在,即可以从重启的B back到A。
Java关键字instanceof
instanceof严格来说是Java中的一个双目运算符,用来判断一个对象是否为一个类的实例 用法:boolean result = obj instance of Class 其中obj为一个对象,Class表示一个类或是一个接口,当obj为Class的对象,或者是其直接或间接子类,或者是其接口的实现类,结果result都会返回true,否则返回false。 编译器会首先检查obj是否能转换成右边的class类型,如果不能则会直接报错,如果不能确定类型,则通过编译。 obj必须为引用类型,不能为基本类型int i = 0;System.out.println(i instanceof Integer); //编译不通过System.out.println(i instanceof Object); //编译不通过 instanceof运算符只能用作对象的判断 obj为nullSystem.out.println(null instanceof Object); //false 在 JavaSE规范 中对 instanceof 运算符的规定就是:如果 obj 为 null,那...
String.format()的使用
当有一个字符串有一部分是固定另外一部分是需要变化的时候,最好使用String.format()来处理这种情况。 格式为String.format(String format, Object ... args) 例如在www.xxx.com/s?index=后面需要添加参数时 String url = "www.xxx.com/s?index=%d" String format = String.format(url,100) System.out.println(format) 执行后即可得到结果www.xxx.com/s?index=100 如在字符串中有多个变化的部分的时候则可以使用以下方法: 例如需要显示距离过年还有xx天xx时xx秒 可以在string.xml中声明 <string name="delay_time">距离过年还有%1$d天%2$d时%3$d秒</string> 在代码中的使用: mTextView.setText(String.format(getResources().ge...
Android如何判断网络状态
在Android版本6.0之前只能使用NetworkInfo获取网络状态 6.0之后NetworkInfo被弃用,应当使用Network来获取 public class NetWorkStateUtils { private final static int NO_NETWORK = 0; private final static int NETWORK_WIFI = 1; private final static int NETWORK_MOBILE = 2; public static int networkConnected(Context context) { ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); //Android版本在6.0之前只能使用NetworkInfo获取网络状态 if (Bu...
Android如何在文本中添加空格
名称 编号 描述     不会被合并的空格,长度与常规空格相同 &ensp   全角空格,长度为半个中文字符 &emsp   全角空格,长度为一个中文字符 \u3000 \u3000 全角空格,长度为一个中文字符
Switch控件过时处理方法
在使用Switch控件时,Android Studio警告Warning : Use SwitchCompat from AppCompat or SwitchMaterial from Material library 应该使用SwitchCompat或者是SwitchMaterial 来代替Switch控件 以下xml为SwitchMaterial <com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/finish_entry_sw" android:layout_width="wrap_content" android:layout_height="match_parent" android:checked="false" android:enabled="true" /> SwitchCompat和SwitchMaterial为旧Sw...
如何在TableLayout的item之间添加分割线
LinearLayout的android:divider属性 这个属性可以在LinearLayout的每个子布局直间添加一个“drawable”作为分割线,这个drawable必须有设定好的高度或者宽度,因此不能直接设置为“@color/….” 这个属性要和android:showDividers一起使用才会生效 android:showDividers有“begining”,“middle”,“end”,“none”四种值。默认值为“none”,即不显示分割线。 android:showDividers属性这个属性可以将定义的divider属性显示出来 android:showDividers=”beginning” 只有第一个子控件上方显示一条分割线 android:showDividers=”middle” 每个子控件之间都会显示一条分割线 android:showDividers=”end” 只有最后一个子控件的下方会显示一条分割线 android:showDividers=”none” 如果不设置此属性则默认为none,即不显示分割线 以上两个属性需设置a...
kotlin基础:int和String的相互转换及kotlin的for循环
int和String的互相转换fun Test() { var a = "13" var b = 13 a = b.toString()//把b数字转换成字符串放进a里面 b = a.toInt() //把a字符串转换成数字放入b里面 kotlin For循环遍历1-100 for (index in 1..100){ print(index)} 对应java的 for (int index = 1; index <= 100; index++){ System.out.print(index + "")} 倒序遍历1-100 for (index in 100 downTo 1){ print(index)} 对应java的 for (int index = 100; index >= 1; i--){ System.out.print(index + "")} 遍历1-100的...
markdown语法如何设置文字颜色大小及字体属性
Typora支持内嵌html语法,因此需要使用html代码来设置 <span style=’color:文字颜色;background:背景颜色;font-size:文字大小;font-family:字体;’>文字</span> 也可参照此网址来快速修改
