華為Scan Kit二維碼掃描 默認(rèn)的 視圖圖標(biāo)文字不能更改观蜗,改動成custom 需要改動太多咧栗,目前僅是想改動頂部提示問題和打開去除打開圖庫按鈕逆甜。
image.png
思路
1.構(gòu)建新的操作的Activity繼承ScanKitActivity
2.獲取顯示視圖的View
3.遍歷顯示視圖的View 的子view 找到顯示控件的地方
4.更改顯示內(nèi)容虱肄。
1.ScanKitActivity源碼分析
public class ScanKitActivity extends Activity {
private RemoteView remoteView;
private ImageView backBtn;
private static final String TAG = "ScanKitActivity";
protected void onCreate(Bundle var1) {
super.onCreate(var1);
this.requestWindowFeature(1);
this.setContentView(layout.scankit_layout);
int var2 = 0;
try {
if (this.getIntent() != null) {
var2 = this.getIntent().getIntExtra("ScanFormatValue", 0);
}
} catch (NullPointerException var6) {
a.b("ScanKitActivity", "getIntExtra can not get");
}
this.remoteView = new RemoteView(this, false, var2, (Rect)null);
this.remoteView.onCreate(var1);
ViewGroup var3 = (ViewGroup)this.findViewById(id.ll_top);
var3.addView(this.remoteView);
........
}
RemoteView 動態(tài)添加到Activity視圖中,所需要改動的在RemoteView 中交煞。
2.實(shí)踐
public class ScanByHWActivity extends ScanKitActivity {
RemoteView remoteViewCurrent;
static String TAG = "ScanByHWActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initview();
}
private void initview() {
ViewGroup var3 = (ViewGroup) this.findViewById(R.id.ll_top);
for (int i = 0; i < var3.getChildCount(); i++) {
View v = var3.getChildAt(i);
if (v instanceof RemoteView) {
remoteViewCurrent = (RemoteView) v;
break;
}
}
if (remoteViewCurrent != null) {
printView(remoteViewCurrent);
}
}
private void printView(ViewGroup viewGroup) {
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View v = viewGroup.getChildAt(i);
if (v instanceof ViewGroup) {
Log.e(TAG, "printView:--viewgroup " + v.getClass().getSimpleName());
printView((ViewGroup) v);
} else {
Log.e(TAG, "printView:- " + v.getClass().getSimpleName());
}
}
}
}
先打印所有的子元素
實(shí)際輸出:
E/ScanByHWActivity: printView:--viewgroup ProviderRemoteView
E/ScanByHWActivity: printView:--viewgroup FrameLayout
E/ScanByHWActivity: printView:- SurfaceView
E/ScanByHWActivity: printView:- ViewfinderView
E/ScanByHWActivity: printView:--viewgroup RelativeLayout
E/ScanByHWActivity: printView:- TextView
E/ScanByHWActivity: printView:- ImageView
E/ScanByHWActivity: printView:- ImageView
E/ScanByHWActivity: printView:--viewgroup LinearLayout
E/ScanByHWActivity: printView:- ImageView
E/ScanByHWActivity: printView:- TextView
一看就知道 可以操作
debug 操作之后咏窿,成功拿到上面如圖的id
android.widget.TextView{3a0914f V.ED..... ......ID 0,0-0,0 #7f090696 app:id/title_scan}
android.widget.ImageView{8834d7d V.ED..... ......I. 0,0-0,0 #7f090047 app:id/back_img_in}
android.widget.ImageView{740ae22 V.ED..C.. ......I. 0,0-0,0 #7f090230 app:id/img_btn}
android.widget.ImageView{a54e3d2 V.ED..C.. ......ID 0,0-0,0 #7f090258 app:id/ivFlash}
android.widget.TextView{1608493 V.ED..... ......ID 0,0-0,0 #7f0901e7 app:id/flash_light_text}
是不是有點(diǎn)不對?明明有三處文字怎么三個圖標(biāo)怎么只有2個textview
繼續(xù)研究發(fā)現(xiàn) 中間展示的文字是在 ViewfinderView里素征。
image.png
并且沒有暴露方法集嵌,對外修改,混淆后的代碼御毅,反射有難度纸淮,
檢查了下源碼
image.png
scankit_scan_tip 字段,那就強(qiáng)制本地編譯用的修改掉亚享,缺點(diǎn) 重新?lián)Q電腦拉取編譯就又回去了咽块。
image.png
上圖就是修改后的。
至此 隱藏圖庫入口就簡單了:不顯示掃碼title 和圖庫入口
if (remoteViewCurrent != null) {
TextView textView = remoteViewCurrent.findViewById(R.id.title_scan);
ImageView img = remoteViewCurrent.findViewById(R.id.img_btn);
textView.setText("");
img.setVisibility(View.GONE);
}
image.png