设置 DialogFragment 的背景颜色透明

原文:https://blog.csdn.net/cc20032706/article/details/51741793
Android 开发中,能否设置 DialogFragment 的背景颜色?
系统默认的过于深了,非常不友好。

解决方案:
1.在DialogFragment的onCreateView里面设置,可以将对话框内部的背景设为透明

getDialog().getWindow().setBackgroundDrawable(newColorDrawable(Color.TRANSPARENT));

2.在DialogFragment的onstart里面设置,可以将对话框外部的背景设为透明

@Override
public void onStart() {
    // TODO Auto-generated method stub
    super.onStart();        
    Window window = getDialog().getWindow();
    WindowManager.LayoutParams windowParams = window.getAttributes();
    windowParams.dimAmount = 0.0f;
    window.setAttributes(windowParams);
}

————————————————
版权声明:本文为CSDN博主「摄氏三十七度」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/cc20032706/article/details/51741793

实测方案1 好用,收藏一下

Android:ClassNotFoundException:Didn't find class "org.apache.http.util.Args"

原文链接:https://blog.csdn.net/qq_33721320/article/details/86620524

在 Android 6.0 中,我们取消了对 Apache HTTP 客户端的支持。 从 Android 9 开始,默认情况下该内容库已从 bootclasspath 中移除且不可用于应用。

要继续使用 Apache HTTP 客户端,以 Android 9 及更高版本为目标的应用可以向其 AndroidManifest.xml的###application节点下 添加以下内容:
<uses-library
    android:name="org.apache.http.legacy"
    android:required="false" />

在application下面添加 uses-library。即可

        <application
            android:name=".MyApp"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:usesCleartextTraffic="true"
            android:theme="@style/AppTheme">
 
            <uses-library
                android:name="org.apache.http.legacy"
                android:required="false" />
 
            <activity
                android:name=".activity.SplashActivity"
                android:exported="true"
                android:screenOrientation="portrait"
                android:theme="@style/Splash">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
 
                    <category android:name="android.intent.category.LAUNCHER" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
 
        </application>
<!--android:usesCleartextTraffic="true"主要是适配9.0的Http网络请求。-->

注:拥有最低 SDK 版本 23 或更低版本的应用需要 android:required="false" 属性,因为在 API 级别低于 24 的设备上,org.apache.http.legacy 库不可用。 (在这些设备上,Apache HTTP 类在 bootclasspath 中提供。)
作为使用运行时 Apache 库的替代,应用可以在其 APK 中绑定自己的 org.apache.http 库版本。 如果进行此操作,您必须将该库重新打包(使用一个类似 Jar Jar 的实用程序)以避免运行时中提供的类存在类兼容性问题。

绕过Android 对非SDK接口的限制

原理见:http://weishu.me/2018/06/07/free-reflection-above-android-p/
使用方法:

//https://github.com/tiann/FreeReflection
implementation 'me.weishu:free_reflection:1.2.0'
然后在application的 attachBaseContext 方法中初始化
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {//9.0
Reflection.unseal(base)
}
注:好像有的系统会闪退
---------------------------------------
可以使用另一个库
//https://github.com/ChickenHook/RestrictionBypass
implementation 'com.github.ChickenHook:RestrictionBypass:2.2'

Android应用第一次安装成功点击“打开”后Home键切出应用后再点击桌面图标返回导致应用重启问题

出处:https://blog.csdn.net/WS1549384743/article/details/51907107

Android系统,用户第一次安装应用在系统的安装器安装完成界面有“完成”和“打开”两个按钮。

当用户点击“打开”按钮并进行了一些操作后,若此时用户点击Home键切出应用到桌面,
再从桌面点击应用程序图标试图切回应用接着刚才的操作继续操作时,应用重新到了初始界面,
此时之前从系统的安装完成界面点击打开启动的应用其实还在后面运行。

然而当用户“完全退出”应用,或者在安装完成界面直接点击“完成”按钮再从桌面启动,
或者此应用之前是存在的“覆盖安装”后点击“打开”按钮都是不会导致应用程序“多次启动”的。
从网上查找资料,说设置activity的launchMode等都不能解决此问题。

查看相关博客资料得知原因:利用程序安装器打开程序,启动的Intent是没有带Category,
而我们自己打开程序是带了Category,所以只需要在配置了Intent.ACTION_MAIN的Activity的
onCreate()方法中的添加下面代码即可。放在super.onCreate(savedInstanceState)方法后。

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
/*
broadcastReceiver的注册要在
if (!isTaskRoot()) {
Intent intent = getIntent();
String action = intent.getAction();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
finish();
return;
}
}
之前,否则或出现以下异常
Caused by: java.lang.IllegalArgumentException: Receiver not registered 广播未注册
*/

// IntentFilter intentFilter = new IntentFilter();
// intentFilter.addAction(VPN_ONLINE_ACTION);
// registerReceiver(broadcastReceiver, intentFilter);

if (!isTaskRoot()) {
    Intent intent = getIntent();
    String action = intent.getAction();
    if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
        finish();
        return;
    }
  }
}

另外,需要注意两点,一是、如果上面的Activity中实现了finish() 和 onDestroy() 方法,一定要保证这两个方法中不会有对空对象的操作以及注销未注册的广播等类似操作,因为第二次打开应用时,程序会调用finish()方法,及触发onDestroy()方法,而这两个函数里面的对象变量都还未进行初始化等操作。二是、finish() 和 onDestroy() 方法中不能有System.exit(0);否则第二次打开应用杀掉进程时也会将第一次打开的应用杀掉。

安卓app检测是否安装微信和支付宝

/**
 * 检测是否安装支付宝
 *
 * @return
 */
public boolean checkAliPayInstalled() {

    Uri uri = Uri.parse("alipays://platformapi/startApp");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    ComponentName componentName = intent.resolveActivity(this.getPackageManager());
    return componentName != null;
}

/**
 * 检测是否安装微信
 * @return
 */
public boolean checkWechatInstalled() {

    Uri uri = Uri.parse("weixin://");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    ComponentName componentName = intent.resolveActivity(this.getPackageManager());
    return componentName != null;
}