小编Nic*_*zzi的帖子

提供不同的构建配置/风格(开发、生产)

在我的 flutter 应用程序中,我有这样的配置:

api_url = https://api.poemhub.top
Run Code Online (Sandbox Code Playgroud)

问题是,在不同的环境下api url是不同的,在开发时,api应该是这样的:

api_url = https://dev-api.poemhub.top
Run Code Online (Sandbox Code Playgroud)

在测试环境中:

api_url = https://beta-api.poemhub.top
Run Code Online (Sandbox Code Playgroud)

在生产环境中:

api_url = https://api.poemhub.top
Run Code Online (Sandbox Code Playgroud)

不同地方的其他配置也不同,那么在不同环境中处理此配置的最佳方法是什么?我已经阅读了一个定义不同main.dart并运行构建命令的解决方案,如下所示:

flutter build apk -t lib/main_develop.dart
Run Code Online (Sandbox Code Playgroud)

flutter

6
推荐指数
1
解决办法
2222
查看次数

5
推荐指数
2
解决办法
8643
查看次数

在 Android Studio 中的自定义视图的编辑器中显示正确的布局

我在 Android Studio 中遇到布局预览的奇怪行为。我开发了一个扩展 AppCompatButton 的自定义视图,并且布局是运行时预期的布局,但是,布局预览中的布局未正确显示。特别是,按钮被显示,但没有从自定义属性设置的背景颜色,也没有 drawableStart(根据名为“social”的自定义属性在自定义视图 init 中设置)。有关其他详细信息,请参阅下面的代码。请注意,自定义视图位于作为模块导入主项目的库中。我在这里缺少什么?谢谢 :)

右侧布局 编辑器(坏)布局

自定义视图代码:

public class SocialButton extends AppCompatButton {
    private static final String TAG = SocialButton.class.getSimpleName();
    Context mContext;
    int backgroundColor;
    int socialId;
    int textColor;

    public SocialButton(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        TypedArray a = context.getTheme().obtainStyledAttributes(
                attrs,
                R.styleable.SocialButton,
                0, 0);
        initDefaults(a);
        setIconForSocial();
        initStateListDrawable();
    }

    public void initDefaults(TypedArray a){
        try {
            backgroundColor = a.getColor(R.styleable.SocialButton_backgroundColor, Color.WHITE);
            textColor = a.getColor(R.styleable.SocialButton_textColor,
                    ContextCompat.getColor(mContext,R.color.social_button_text_color));
            socialId = a.getInt(R.styleable.SocialButton_social, 0);
        } finally {
            a.recycle();
        }
    } …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view android-layout-editor

5
推荐指数
0
解决办法
582
查看次数

Google Play开发者控制台上的Apk上传无法正常运行

这里有个奇怪的问题.我在Google Play上部署了一个应用程序.来自Google Play开发者控制台我正在尝试使用新的apk(版本代码22与版本代码21)更新我的应用的当前版本,但是,上传失败并显示通用的"上传错误"消息.我已经尝试启动lint命令,它构建项目没有任何错误.有人有任何想法吗?谢谢

在此输入图像描述

android google-play-console

5
推荐指数
1
解决办法
1218
查看次数

在Android Studio中的不同开发人员计算机之间共享android调试证书

当同一部手机连接到不同的MacBooks时,由于要重新安装Android调试版本,所有开发机器(MacBooks)是否可以共享同一调试证书?这将有助于避免在开发设备上重新安装。

android android-studio android-gradle-plugin android-app-signing

5
推荐指数
2
解决办法
437
查看次数

在协程中切换到 UI 上下文

我是协程新手,我想知道是否可以将下面的代码从 coroutineScope (GlobalScope) 切换到 UI 范围。我的问题是协程启动体内的步骤必须在工作线程中执行,否则监听器通知必须在 ui 线程中执行,以避免在我的活动代码中调用 runOnUiThread。

override suspend fun startRent(name: String, bikeMode: BikeMode, listener: StartRentListener) {
        var bleDevice : RxBleDevice
        val scanFilter: ScanFilter = ScanFilter.Builder().setDeviceName(name).build()
        val scanSettings: ScanSettings = ScanSettings.Builder().build()

        val job = GlobalScope.launch {
            try {
                bleDevice = rxBleClient.scanBleDevicesExt(rxBleClient, scanSettings, scanFilter)
                val bleConnection = bleDevice.establishConnectionExt()
                // write handshake
                connectionManager.writeHandshake(bleDevice, bleConnection)
                // open lock
                openLock(bleDevice, bikeMode, bleConnection)
                // getting user position
                apiHelper.sendLockRequest(bleDevice.name, getPosition())
                bleDevice.disconnect()
                // this should be called on main thread once all the previous operations …
Run Code Online (Sandbox Code Playgroud)

android kotlin kotlinx.coroutines

5
推荐指数
1
解决办法
6331
查看次数

Kotlin可以定义为强类型语言吗?

从强类型语言的定义:

强类型编程语言是指每种类型的数据(例如整数,字符,十六进制,压缩十进制等)被预定义为编程语言的一部分,并且为给定程序定义的所有常量或变量必须是用其中一种数据类型描述(来源)

从kotlin文档中,我可以理解kotlin是一种静态类型语言,因为变量的类型在编译时是已知的,但是强类型还是弱类型呢?我找不到任何明确的回复谷歌搜索.据我所知,Kotlin应该与Java一样强类型,因为它编译为Java字节代码,但我不是100%肯定.请帮助我理解我是否正确的方式.

strong-typing kotlin

4
推荐指数
1
解决办法
564
查看次数

自定义视图中的渐变文本颜色

我有这个 GradientTextView 类,它扩展了 AppCompatTextView

public class GradientTextView extends android.support.v7.widget.AppCompatTextView {

public GradientTextView(Context context) {
    super(context);
}

public GradientTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public GradientTextView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    //Setting the gradient if layout is changed
    if (changed) {
        getPaint().setShader(new LinearGradient(0, 0, getWidth(), getHeight(),
                ContextCompat.getColor(getContext(), R.color.colorStart),//Red Color
                ContextCompat.getColor(getContext(), R.color.colorEnd),// Blue Color
                Shader.TileMode.CLAMP));
    } …
Run Code Online (Sandbox Code Playgroud)

android gradient textview android-custom-view

4
推荐指数
1
解决办法
1095
查看次数

cardBackgroundColor 和 cardCornerRadius 在 AndroidX 中不起作用

我正在努力解决 CardView 角半径和背景颜色与 AndroidX 库的问题。

我的布局定义如下:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
        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"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="@dimen/retail_card_width"
        card_view:cardCornerRadius="@dimen/card_radius"
        card_view:cardBackgroundColor="@color/baseYellow"
        android:layout_height="@dimen/retail_card_height">
    <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <ImageView android:layout_width="match_parent" android:layout_height="match_parent"
                   tools:src="@drawable/ic_fruit_1"
                   app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"
                   app:layout_constraintStart_toStartOf="parent"
                   android:scaleType="fitEnd"
                   app:layout_constraintTop_toTopOf="parent"/>
        <ImageView
                android:id="@+id/ivRetailBrand"
                android:layout_width="@dimen/brand_icon_size"
                android:layout_height="@dimen/brand_icon_size"
                tools:src="@drawable/esselunga"
                android:layout_marginTop="@dimen/retail_brand_margin"
                android:background="@drawable/round_outline"
                app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
                android:layout_marginStart="@dimen/retail_brand_margin"/>
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

不幸的是,我的布局似乎cardCornerRadius也没有cardBackgroundColor工作。我不明白我的问题是否依赖于 AndroidX 库。

这是我的布局预览:

卡片视图问题

android android-cardview androidx

4
推荐指数
1
解决办法
1万
查看次数

为全局操作弹出图形 startDestination 片段 - Android 导航组件

我有一个多图导航应用程序,我想使用global action根目录中定义的a 在图之间切换main_graph.xml

<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/main_graph"
        app:startDestination="@id/loadingFragment">

    <include app:graph="@navigation/learn_graph" />

    <action
            android:id="@+id/action_global_learn_graph"
            app:destination="@id/learn_graph"
            app:launchSingleTop="true"
            />
</navigation>
Run Code Online (Sandbox Code Playgroud)

由于我正在尝试在图形之间切换,因此在将全局操作导航到目标图形 (explore_graph) 时,我想从源图形 (main_graph) 加载的片段中清除返回堆栈。预期的行为是导航到startDestination目标图的片段,仅在后台堆栈中保留该片段。对于正常操作(同一图中的操作),我可以使用popUpTo标志,如何为全局操作获得相同的行为?

navigation android android-jetpack android-architecture-navigation androidx

4
推荐指数
1
解决办法
2572
查看次数