0
点赞
收藏
分享

微信扫一扫

一个activity显示另一个activity,Android studio将一个项目作为module导入另一个项目,字符串截取的几种基本方法

LocalActivityManager实例化不是通过ActivityGroup

LocalActivityManager activity嵌套activity

Android给我们提供了ActivityGroup和TabActivity,当我们至需要嵌套一个Activity或者不方便继承ActivityGroupF的时候,我们可以参考ActivityGroup的实现,比较关键的是LocalActivityManager。

最外层Activity

LocalActivityManager.startActivity()需要传入里程Activity信息,就跟Activity.startActivity()打开新的Activity的Intent参数一样,不同的是LocalActivityManager.startActivity()把传入的Activity信息作为嵌套Activity打开。

外层Activity布局文件可以随意布置,但记得包涵里层Activty的布局标签,就像View是不能正常打开的里层Activity的。

外层Activity布局文件除了FrameLayout还可以使用LinearLayout作为显示里层Activity的视图。

但是里层Activity如果是ListActivity或者关于List相关属性的都不能正常显示。

通过 继承 AppCompatActivity 而不是ActivityGroup

class CeShi  extends AppCompatActivity{

LocalActivityManager mLocalActivityManager;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ce_shi);
mLocalActivityManager = new LocalActivityManager((Activity) this, true);

LinearLayout linear= (LinearLayout) findViewById(R.id.ll_view);
// LocalActivityManager local= getLocalActivityManager();
mLocalActivityManager.dispatchCreate(savedInstanceState);
linear.addView((mLocalActivityManager.startActivity("OtherActivityView", new Intent(this, RegisterAndRecognizeActivity.class))).getDecorView());


}
}

layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="MissingDefaultResource">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="444dp"
android:id="@+id/ll_view"
android:orientation="horizontal" />

<FrameLayout
android:layout_width="match_parent"
android:layout_height="344dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"/>
<TextureView
android:id="@+id/single_camera_texture_preview"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<com.arcsoft.arcfacedemo.widget.FaceRectView
android:id="@+id/single_camera_face_rect_view"
android:layout_width="match_parent"
android:layout_height="match_parent"

通过 继承 ActivityGroup

/**
* @ProjectName: ArcfaceDemo
* @Package: com.arcsoft.arcfacedemo.activity
* @ClassName: CeShi
* @Description: java类作用描述
* @Author: liys
* @CreateDate: 2021/6/19 8:32
* @UpdateUser: 更新者
* @UpdateDate: 2021/6/19 8:32
* @UpdateRemark: 更新说明
* @Version: 1.0
*/
public class CeShi extends ActivityGroup {
@Override
protected void onCreate(@Nullable {
super.onCreate(savedInstanceState);
setContentView(R.layout.ce_shi);
LinearLayout linear= (LinearLayout) findViewById(R.id.ll_view);
LocalActivityManager local= getLocalActivityManager();
local.dispatchCreate(savedInstanceState);


linear.addView((local.startActivity("OtherActivityView", new Intent(this, RegisterAndRecognizeActivity.class))).getDecorView());

}
}

studio将一个项目作为module导入另一个项目

apply plugin: ‘com.android.application’ 为 apply plugin: ‘com.android.library’

一个activity显示另一个activity,Android studio将一个项目作为module导入另一个项目,字符串截取的几种基本方法_字符串


一个activity显示另一个activity,Android studio将一个项目作为module导入另一个项目,字符串截取的几种基本方法_嵌套_02


一个activity显示另一个activity,Android studio将一个项目作为module导入另一个项目,字符串截取的几种基本方法_Android_03


一个activity显示另一个activity,Android studio将一个项目作为module导入另一个项目,字符串截取的几种基本方法_Android_04


一个activity显示另一个activity,Android studio将一个项目作为module导入另一个项目,字符串截取的几种基本方法_嵌套_05

删除子module的 application

一个activity显示另一个activity,Android studio将一个项目作为module导入另一个项目,字符串截取的几种基本方法_Android_06

字符串截取的几种基本方法

public static void main(String[] args) {
String a="abcd-efg";
String a1=a.substring(a.lastIndexOf("-")+1);
String a2=a.substring(0,a.indexOf("-"));
System.out.println(a1);//efg
System.out.println(a2);//abcd
String b="620303197010141212";
if(b.length() == 18){
String sex = b.substring(16, 17);
System.out.println(sex);
if(Integer.parseInt(sex)%2==0){
enfore_sex.setText("女");
}else{
enfore_sex.setText("男");
}
}

String c="陕C38205(黄)色";
String c1=c.substring(c.lastIndexOf(")")+1);
String c2=c.substring(0,c.indexOf("("));
String c3=c.replace("(","");
c3=c3.replace(")","");
String c5=c.substring(c.indexOf("(")+1,c.indexOf(")"));
System.out.println(c1);//色
System.out.println(c2);//陕C38205
System.out.println(c3);//陕C38205黄色
System.out.println(c5);//黄

string str=“123abc456”;

int i=3;

1 取字符串的前i个字符

str=str.Substring(0,i); // or str=str.Remove(i,str.Length-i);2 去掉字符串的前i个字符:

str=str.Remove(0,i); // or str=str.Substring(i);3 从右边开始取i个字符:

str=str.Substring(str.Length-i); // or str=str.Remove(0,str.Length-i);4 从右边开始去掉i个字符:

str=str.Substring(0,str.Length-i); // or str=str.Remove(str.Length-i,i);5 判断字符串中是否有"abc" 有则去掉之

using System.Text.RegularExpressions;

string str = “123abc456”;

string a=“abc”;

Regex r = new Regex(a);

Match m = r.Match(str);

if (m.Success)

{

//绿色部分与紫色部分取一种即可。

str=str.Replace(a,“”);

Response.Write(str);

string str1,str2;

str1=str.Substring(0,m.Index);

str2=str.Substring(m.Index+a.Length,str.Length-a.Length-m.Index);

Response.Write(str1+str2);

}6 如果字符串中有"abc"则替换成"ABC"

str=str.Replace(“abc”,“ABC”);string str=“adcdef”; int indexStart = str.IndexOf(“d”);
int endIndex =str.IndexOf(“e”);
string toStr = str.SubString(indexStart,endIndex-indexStart);
c#截取字符串最后一个字符的问题!
str1.Substring(str1.LastIndexOf(“,”)+1)

举报

相关推荐

0 条评论