【移花接木】纯smali添加启动图【精】
本帖最后由 Kid 于 2015-2-3 10:19 编辑之前看到 法总发的添加启动图的帖子看到要添加id, 布局什么的 我之前也这样搞过 对于我这种懒人来说 感觉有的繁琐
大体流程 修改描述文件的信息让他先启动我们的类, 在类中加载一张全屏图片 (或添加个注册界面什么的都可以 ) 然后再跳转到原主界面
①把图片放到assets目录下 没有的新建一个assets目录 把图片命名为 Sc1.png(也可以命名为其他 需要修改 MyMainActivity.smali )
② 修改AndroidManifest.xml把主界面
<activity里的android:name="@@@@@@@@@@"
换成我们的
android:name="com.MyMainActivity"
然后紧挨着下面添加一个
<activityandroid:label="@string/app_name" android:name="@@@这里放原来的主界面类@@@" ></activity>
修改前
修改后
③把
MyMainActivity.smali 和
MyMainActivity$100000000.smali放到smali/com/ 目录下
MyMainActivity.smali代码如下
.class public Lcom/MyMainActivity;
.super Landroid/app/Activity;
.source "MyMainActivity.java"
# annotations
.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lcom/MyMainActivity$100000000;
}
.end annotation
# instance fields
.field image:Landroid/widget/ImageView;
# direct methods
.method public constructor <init>()V
.locals 3
move-object v0, p0
move-object v2, v0
invoke-direct {v2}, Landroid/app/Activity;-><init>()V
return-void
.end method
# virtual methods
.method public mActivity()V
.locals 12
.annotation system Ldalvik/annotation/Signature;
value = {
"()V"
}
.end annotation
move-object v0, p0
new-instance v4, Landroid/content/Intent;
move-object v11, v4
move-object v4, v11
move-object v5, v11
move-object v6, v0
:try_start_0
const-string v7, "com.mycompany.myapp2.MainActivity"#################这是要跳转的原主界面
invoke-static {v7}, Ljava/lang/Class;->forName(Ljava/lang/String;)Ljava/lang/Class;
:try_end_0
.catch Ljava/lang/ClassNotFoundException; {:try_start_0 .. :try_end_0} :catch_0
move-result-object v7
invoke-direct {v5, v6, v7}, Landroid/content/Intent;-><init>(Landroid/content/Context;Ljava/lang/Class;)V
move-object v1, v4
move-object v4, v0
move-object v5, v1
invoke-virtual {v4, v5}, Lcom/MyMainActivity;->startActivity(Landroid/content/Intent;)V
move-object v4, v0
invoke-virtual {v4}, Lcom/MyMainActivity;->finish()V
return-void
:catch_0
move-exception v4
move-object v2, v4
new-instance v4, Ljava/lang/NoClassDefFoundError;
move-object v11, v4
move-object v4, v11
move-object v5, v11
move-object v6, v2
invoke-virtual {v6}, Ljava/lang/Throwable;->getMessage()Ljava/lang/String;
move-result-object v6
invoke-direct {v5, v6}, Ljava/lang/NoClassDefFoundError;-><init>(Ljava/lang/String;)V
throw v4
nop
.end method
.method public onCreate(Landroid/os/Bundle;)V
.locals 14
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Landroid/os/Bundle;",
")V"
}
.end annotation
move-object v0, p0
move-object v1, p1
move-object v9, v0
move-object v9, v0
move-object v10, v1
invoke-super {v9, v10}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V
move-object v9, v0
invoke-virtual {v9}, Lcom/MyMainActivity;->getWindow()Landroid/view/Window;
move-result-object v9
const/16 v10, 0x400
const/16 v11, 0x400
invoke-virtual {v9, v10, v11}, Landroid/view/Window;->setFlags(II)V
move-object v9, v0
const/4 v10, 0x1
invoke-virtual {v9, v10}, Lcom/MyMainActivity;->requestWindowFeature(I)Z
move-result v9
new-instance v9, Landroid/widget/LinearLayout;
move-object v13, v9
move-object v9, v13
move-object v10, v13
move-object v11, v0
invoke-direct {v10, v11}, Landroid/widget/LinearLayout;-><init>(Landroid/content/Context;)V
move-object v2, v9
new-instance v9, Landroid/widget/LinearLayout$LayoutParams;
move-object v13, v9
move-object v9, v13
move-object v10, v13
const/4 v11, -0x1
const/4 v12, -0x1
invoke-direct {v10, v11, v12}, Landroid/widget/LinearLayout$LayoutParams;-><init>(II)V
move-object v3, v9
move-object v9, v0
invoke-virtual {v9}, Lcom/MyMainActivity;->getAssets()Landroid/content/res/AssetManager;
move-result-object v9
move-object v4, v9
const/4 v9, 0x0
check-cast v9, Ljava/io/InputStream;
move-object v5, v9
move-object v9, v4
:try_start_0
const-string v10, "Sc1.png"################这是图片名
invoke-virtual {v9, v10}, Landroid/content/res/AssetManager;->open(Ljava/lang/String;)Ljava/io/InputStream;
move-result-object v9
move-object v5, v9
new-instance v9, Landroid/widget/ImageView;
move-object v13, v9
move-object v9, v13
move-object v10, v13
move-object v11, v0
invoke-direct {v10, v11}, Landroid/widget/ImageView;-><init>(Landroid/content/Context;)V
move-object v6, v9
move-object v9, v6
sget-object v10, Landroid/widget/ImageView$ScaleType;->FIT_XY:Landroid/widget/ImageView$ScaleType;
invoke-virtual {v9, v10}, Landroid/widget/ImageView;->setScaleType(Landroid/widget/ImageView$ScaleType;)V
move-object v9, v6
move-object v10, v5
invoke-static {v10}, Landroid/graphics/BitmapFactory;->decodeStream(Ljava/io/InputStream;)Landroid/graphics/Bitmap;
move-result-object v10
invoke-virtual {v9, v10}, Landroid/widget/ImageView;->setImageBitmap(Landroid/graphics/Bitmap;)V
new-instance v9, Landroid/widget/LinearLayout$LayoutParams;
move-object v13, v9
move-object v9, v13
move-object v10, v13
const/4 v11, -0x1
const/4 v12, -0x1
invoke-direct {v10, v11, v12}, Landroid/widget/LinearLayout$LayoutParams;-><init>(II)V
move-object v7, v9
move-object v9, v2
move-object v10, v6
move-object v11, v7
invoke-virtual {v9, v10, v11}, Landroid/widget/LinearLayout;->addView(Landroid/view/View;Landroid/view/ViewGroup$LayoutParams;)V
move-object v9, v0
move-object v10, v2
move-object v11, v3
invoke-virtual {v9, v10, v11}, Lcom/MyMainActivity;->setContentView(Landroid/view/View;Landroid/view/ViewGroup$LayoutParams;)V
new-instance v9, Landroid/os/Handler;
move-object v13, v9
move-object v9, v13
move-object v10, v13
invoke-direct {v10}, Landroid/os/Handler;-><init>()V
new-instance v10, Lcom/MyMainActivity$100000000;
move-object v13, v10
move-object v10, v13
move-object v11, v13
move-object v12, v0
invoke-direct {v11, v12}, Lcom/MyMainActivity$100000000;-><init>(Lcom/MyMainActivity;)V
const/16 v11, 0x7d0###############这是要显示的时长
int-to-long v11, v11
invoke-virtual {v9, v10, v11, v12}, Landroid/os/Handler;->postDelayed(Ljava/lang/Runnable;J)Z
:try_end_0
.catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0
move-result v9
:goto_0
return-void
:catch_0
move-exception v9
move-object v6, v9
move-object v9, v0
invoke-virtual {v9}, Lcom/MyMainActivity;->mActivity()V
goto :goto_0
nop
.end method
******然后修改 MyMainActivity.smali 里的mActivity方法 把里面
const-string v7, "com.mycompany.myapp2.MainActivity" 修改为需要跳转到的原主界面
******修改图片名 往下找
const-string v10, "Sc1.png" 这是你添加的图片名字 自由修改 名字保持一致就好
******修改显示时间 往下找
const/16 v11, 0x7d0
这里的0x7d0是2000毫秒 也就是 2秒
MyMainActivity$100000000.smali代码如下
.class Lcom/MyMainActivity$100000000;
.super Ljava/lang/Object;
.source "MyMainActivity.java"
# interfaces
.implements Ljava/lang/Runnable;
# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
value = Lcom/MyMainActivity;
.end annotation
.annotation system Ldalvik/annotation/InnerClass;
accessFlags = 0x20
name = "100000000"
.end annotation
# instance fields
.field private final this$0:Lcom/MyMainActivity;
# direct methods
.method constructor <init>(Lcom/MyMainActivity;)V
.locals 5
move-object v0, p0
move-object v1, p1
move-object v3, v0
invoke-direct {v3}, Ljava/lang/Object;-><init>()V
move-object v3, v0
move-object v4, v1
iput-object v4, v3, Lcom/MyMainActivity$100000000;->this$0:Lcom/MyMainActivity;
return-void
.end method
.method static access$0(Lcom/MyMainActivity$100000000;)Lcom/MyMainActivity;
.locals 4
move-object v0, p0
move-object v3, v0
iget-object v3, v3, Lcom/MyMainActivity$100000000;->this$0:Lcom/MyMainActivity;
move-object v0, v3
return-object v0
.end method
# virtual methods
.method public run()V
.locals 3
.annotation system Ldalvik/annotation/Signature;
value = {
"()V"
}
.end annotation
move-object v0, p0
move-object v2, v0
iget-object v2, v2, Lcom/MyMainActivity$100000000;->this$0:Lcom/MyMainActivity;
invoke-virtual {v2}, Lcom/MyMainActivity;->mActivity()V
return-void
.end method
添加启动图的前后文件。。。可以手动练练
链接: http://pan.baidu.com/s/1bntUIlx 密码: x5l1
这个必须顶!! 不错学习了~谢谢分享 赞一个,期待更多的移花接木..
谢谢分享了{:4_87:} 谢谢经验分享,辛苦了! 必须顶 很好很强大。支持一下。 不错啊顶你楼主 一想到移花接木,我立马想到淡然,没想到不是,高手在民间。
页:
[1]
2