gradle new File报错 安卓应用开发

android.applicationVariants.all { variant -> def variantName = variant.name.capitalize() def mergeTask = tasks["merge${variantName}Assets"] def processTask = tasks["process${variantName}Resources"] def outFile = new File (mergeTask.outputDir.getAsFile().get(), "xwalk-command-line") def newTask = project.task("createXwalkCommandLineFile${variantName}") doLast {
        mergeTask.outputDir.mkdirs()
        outFile.write("xwalk ${xwalkCommandLine}\n")
    }
    newTask.dependsOn(mergeTask)
    processTask.dependsOn(newTask)
}

new 发布于 2020-8-5 06:20

adb devices没有发现设备 安卓应用开发

问题现象:在电脑上安装好手机驱动后,手机进入设置---->应用程序---->开发----->勾选USB调试后连接电脑,,在CMD命令中输入adb devices发现没有设备。

 

解决方法:开始菜单-->计算机(右键)-->设备管理器,找到设备,如下图

 

双击设备驱动,在弹出的菜单中选中“详细信息”tab页。

 

在下拉菜单中选中“硬件 Id”

 

 

记录VID后的数字,此处为1EBF.

 

在C:\Users\lenovo\.android文件夹中找到adb_usb.ini文件,打开,在文件中添加刚才找到的数字1EBF,保存

 

开启CMD,输入adb kill-server关闭服务后再输入 adb start-server开启服务,此时输入adb shell就可以看到设备了。


new 发布于 2020-5-22 03:19

Android 对apk进行重签名和查看签名(window 和mac)及生成签名 安卓应用开发

生成签名文件

keytool -genkey -alias xxxx.keystore -keyalg RSA -validity 2000 -keystore newandroid.keystore

PS:-alias后面跟着的是别名(android.keystore) -keystore后面跟着的是具体的签名文件(及签名文件的命名–newandroid.keystore)


查看签名和重签名:

使用JDK下keytool


keytool -list -v -keystore xxxx.keystore

查看apk的签名信息:

第一步:将apk解压

第二步:找到META-INF 下的.RSA文件

第三步:在mac终端或者window控制器上输入命令:

keytool -printcert -file xxx.RSA回车,即可查看签名信息(MD5)



new 发布于 2019-9-25 01:06

cordova mismatch of cpu architecture问题的解决 安卓应用开发

在项目目录下的config.xml下添加


<preference name="xwalkMultipleApk" value="false" />


new 发布于 2018-11-1 06:49

使用Fragment实现底部Tab标签切换界面功能 安卓应用开发

使用Fragment实现底部Tab标签切换界面功能

主界面布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.loccy.loccy.MainActivity">
    <RelativeLayout
        android:id="@+id/rl_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!--<RelativeLayout-->
            <!--android:id="@+id/top_tab"-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="50dip"-->
            <!--android:background="#948a8a">-->
            <!--<ImageView-->
                <!--android:id="@+id/logo"-->
                <!--android:layout_width="match_parent"-->
                <!--android:layout_height="match_parent"-->
                <!--android:layout_centerInParent="true"-->
                <!--android:background="#f00"/>-->
        <!--</RelativeLayout>-->
        <LinearLayout
            android:id="@+id/ll_bottom_tab"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:baselineAligned="true"
            android:background="#dadada">
            <RelativeLayout
                android:id="@+id/rl_tab_homepage"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1">
                <ImageView
                    android:id="@+id/iv_tab_homepage"
                    android:layout_width="26dp"
                    android:layout_height="26dp"
                    android:paddingTop="5dp"
                    android:layout_centerHorizontal="true"
                    android:src="@drawable/tab_homepage_checked"
                    android:contentDescription="@null"/>
                <TextView
                    android:id="@+id/tv_tab_homepage"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingBottom="3dp"
                    android:layout_below="@+id/iv_tab_homepage"
                    android:layout_centerHorizontal="true"
                    android:text="@string/tab_homepage"
                    android:textColor="@color/tab_item_checked"
                    android:textSize="14sp"/>
            </RelativeLayout>
            <RelativeLayout
                android:id="@+id/rl_tab_activity"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1">
                <ImageView
                    android:id="@+id/iv_tab_activity"
                    android:layout_width="26dp"
                    android:layout_height="26dp"
                    android:paddingTop="5dp"
                    android:layout_centerHorizontal="true"
                    android:src="@drawable/tab_me_normal"
                    android:contentDescription="@null"/>
                <TextView
                    android:id="@+id/tv_tab_activity"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingBottom="3dp"
                    android:layout_below="@+id/iv_tab_activity"
                    android:layout_centerHorizontal="true"
                    android:text="@string/tab_activity"
                    android:textColor="@color/tab_item_normal"
                    android:textSize="14sp"/>
            </RelativeLayout>
            <RelativeLayout
                android:id="@+id/rl_tab_message"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1">
                <ImageView
                    android:id="@+id/iv_tab_message"
                    android:layout_width="26dp"
                    android:layout_height="26dp"
                    android:paddingTop="5dp"
                    android:layout_centerHorizontal="true"
                    android:src="@drawable/tab_message_normal"
                    android:contentDescription="@null"/>
                <TextView
                    android:id="@+id/tv_tab_message"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingBottom="3dp"
                    android:layout_below="@+id/iv_tab_message"
                    android:layout_centerHorizontal="true"
                    android:text="@string/tab_message"
                    android:textColor="@color/tab_item_normal"
                    android:textSize="14sp"/>
            </RelativeLayout>
            <RelativeLayout
                android:id="@+id/rl_tab_me"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1">
                <ImageView
                    android:id="@+id/iv_tab_me"
                    android:layout_width="26dp"
                    android:layout_height="26dp"
                    android:paddingTop="5dp"
                    android:layout_centerHorizontal="true"
                    android:src="@drawable/tab_me_normal"
                    android:contentDescription="@null"/>
                <TextView
                    android:id="@+id/tv_tab_me"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingBottom="3dp"
                    android:layout_below="@+id/iv_tab_me"
                    android:layout_centerHorizontal="true"
                    android:text="@string/tab_me"
                    android:textColor="@color/tab_item_normal"
                    android:textSize="14sp"/>
            </RelativeLayout>
        </LinearLayout>
        <View
            android:id="@+id/line"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_above="@id/ll_bottom_tab"
            android:background="#cfcece">
        </View>
        <LinearLayout
            android:id="@+id/content_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/line"
            android:orientation="vertical">
        </LinearLayout>
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>


主Activity控制切换

package com.loccy.loccy;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private RelativeLayout tab_homepage_lt,tab_activity_lt,tab_message_lt,tab_me_lt;
    private Fragment homepage_fm,activity_fm,message_fm,me_fm,curFragment;
    private static final int TABCOUNT = 4;
    private ImageView[] tab_item_imgs = new ImageView[TABCOUNT];
    private TextView[] tab_item_txts = new TextView[TABCOUNT];
    private int[] img_ids = new int[]{R.id.iv_tab_homepage,R.id.iv_tab_activity,R.id.iv_tab_message,R.id.iv_tab_me};
    private int[] txt_ids = new int[]{R.id.tv_tab_homepage,R.id.tv_tab_activity,R.id.tv_tab_message,R.id.tv_tab_me};
    private int[] img_nor_ids = new int[]{R.drawable.tab_homepage_normal,R.drawable.tab_me_normal,R.drawable.tab_message_normal,R.drawable.tab_me_normal};
    private int[] img_chd_ids = new int[]{R.drawable.tab_homepage_checked,R.drawable.tab_me_checked,R.drawable.tab_message_checked,R.drawable.tab_me_checked};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        InitUI();
        InitTab();
    }
    void InitUI(){
        tab_homepage_lt = (RelativeLayout)findViewById(R.id.rl_tab_homepage);
        tab_activity_lt = (RelativeLayout)findViewById(R.id.rl_tab_activity);
        tab_message_lt = (RelativeLayout)findViewById(R.id.rl_tab_message);
        tab_me_lt = (RelativeLayout)findViewById(R.id.rl_tab_me);
        tab_homepage_lt.setOnClickListener(this);
        tab_activity_lt.setOnClickListener(this);
        tab_message_lt.setOnClickListener(this);
        tab_me_lt.setOnClickListener(this);
        for(int i=0;i<TABCOUNT;i++){
            tab_item_imgs[i] = (ImageView)findViewById(img_ids[i]);
            tab_item_txts[i] = (TextView)findViewById(txt_ids[i]);
        }
    }
    void InitTab() {
        if (homepage_fm == null)
            homepage_fm = new HomeFragment();
        if(!homepage_fm.isAdded()){
            getSupportFragmentManager().beginTransaction().add(R.id.content_layout,homepage_fm).commit();
            curFragment = homepage_fm;
            for(int i=0;i<TABCOUNT;i++){
                if(i==0){
                    tab_item_imgs[i].setImageResource(img_chd_ids[i]);
                    tab_item_txts[i].setTextColor(getResources().getColor(R.color.tab_item_checked));
                }
                else {
                    tab_item_imgs[i].setImageResource(img_nor_ids[i]);
                    tab_item_txts[i].setTextColor(getResources().getColor(R.color.tab_item_normal));
                }
            }
        }
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.rl_tab_homepage:onClickTab(0);break;
            case R.id.rl_tab_activity:onClickTab(1);break;
            case R.id.rl_tab_message:onClickTab(2);break;
            case R.id.rl_tab_me:onClickTab(3);break;
        }
    }
    void onClickTab(int index){
        switch (index){
            case 0:{
                if (homepage_fm == null)
                    homepage_fm = new HomeFragment();
                addOrShowFragment(homepage_fm);
            }
            break;
            case 1:{
                if (activity_fm == null)
                    activity_fm = new ActivityFragment();
                addOrShowFragment(activity_fm);
            }
            break;
            case 2:{
                if (message_fm == null)
                    message_fm = new MessageFragment();
                addOrShowFragment(message_fm);
            }
            break;
            case 3:{
                if (me_fm == null)
                    me_fm = new MeFragment();
                addOrShowFragment(me_fm);
            }
            break;
            default:break;
        }
        for(int i=0;i<TABCOUNT;i++){
            if(i==index){
                tab_item_imgs[i].setImageResource(img_chd_ids[i]);
                tab_item_txts[i].setTextColor(getResources().getColor(R.color.tab_item_checked));
            }
            else {
                tab_item_imgs[i].setImageResource(img_nor_ids[i]);
                tab_item_txts[i].setTextColor(getResources().getColor(R.color.tab_item_normal));
            }
        }
    }
    private void addOrShowFragment(Fragment fragment){
        if(curFragment==fragment)
            return;
        if(!fragment.isAdded()) {
            getSupportFragmentManager().beginTransaction().hide(curFragment).add(R.id.content_layout, fragment).commit();
        }
        else {
            getSupportFragmentManager().beginTransaction().hide(curFragment).show(fragment).commit();
        }
        curFragment = fragment;
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Fragment布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
        android:id="@+id/top_tab"
        android:layout_width="match_parent"
        android:layout_height="50dip"
        android:background="#948a8a"
        android:layout_weight="1">
        <ImageView
            android:id="@+id/logo"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            android:background="#837a7a"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/tab_homepage"
            android:textColor="@color/white"
            android:textSize="24sp"/>
        <Button
            android:id="@+id/locate_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:background="#0000"
            android:text="深圳"
            android:textSize="24sp"/>
    </RelativeLayout>
</LinearLayout>

Fragment代码

package com.loccy.loccy;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

/**
* Created by Loccy on 16/3/17.
*/
public class HomeFragment extends Fragment{

private Button search_btn,locate_btn;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//return super.onCreateView(inflater, container, savedInstanceState);

View view = inflater.inflate(R.layout.fragment_homepage,container,false);

locate_btn = (Button)view.findViewById(R.id.locate_btn);
locate_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getContext(), "Locate", Toast.LENGTH_SHORT).show();
}
});
return view;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
标签: Android Tab

new 发布于 2016-3-18 00:40