小编Nic*_*hek的帖子

如何在显示小吃栏时推送现有视图?

这是我尝试在snackbar可见时向上推"NEXT"按钮:

如您所见,它无法按计划运行.看起来似乎textview被推到了后面RelativeLayout然后在snackbar消失时重新出现.相反,我想要的是textview出现向上推(因此它在上方snackbar),然后在snackbar消失时再回来.我还创建了一个小的github repo来证明这一点:

https://github.com/Winghin2517/TestFabMotion

这是CoordinatorLayout.Behavior我用于"NEXT"隐藏自己.当snackbar出现时,当它被推高时,行为取自FAB行为:

public class FloatingActionButtonBehavior extends CoordinatorLayout.Behavior<TextView> {

    public FloatingActionButtonBehavior(Context context, AttributeSet attrs) {
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, TextView child, View dependency) {

        return dependency instanceof Snackbar.SnackbarLayout;
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, TextView child, View dependency) {

        float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight());
        child.setTranslationY(translationY);
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

我用这个xml试过这个:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android behavior android-snackbar android-coordinatorlayout

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

删除scrollFlags`roll`后为什么要拖动内容?

如果在工具栏中删除了app:layout_scrollFlagsscroll,则内容将移至顶部.见截图

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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"
    android:orientation="vertical">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <!--region Content-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <!--region EmptyView-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical"
                android:padding="16dp">

                <TextView
                    android:id="@+id/titleView"
                    fontPath="@string/font_semibold"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:gravity="center"
                    android:padding="8dp"
                    android:textColor="#9b9b9b"
                    android:textSize="16sp"
                    tools:ignore="MissingPrefix"
                    tools:text="@string/error_view_internet_connection_title"/>

                <TextView
                    android:id="@+id/messageView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="32dp"
                    android:gravity="center"
                    android:paddingStart="32dp"
                    android:paddingEnd="32dp"
                    android:textColor="#9b9b9b"
                    android:textSize="14sp"
                    tools:ignore="MissingPrefix"
                    tools:text="@string/error_view_internet_connection_message"
                    />

            </LinearLayout>
            <!--endregion-->

            <!--region List-->
            <android.support.v4.widget.SwipeRefreshLayout
                android:id="@+id/swipeRefreshLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <RecyclerView
                    android:id="@+id/recyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:clipToPadding="false"
                    android:scrollbarSize="2dp"
                    android:scrollbars="vertical"
                    android:visibility="gone"
                    tools:visibility="visible"/> …
Run Code Online (Sandbox Code Playgroud)

xml android-layout android-toolbar android-coordinatorlayout

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

为什么 ContentResolver 看不到其他应用程序添加的文件?

Documents/MyExcelsFolder 我通过使用添加了文件ContentResolver.insert,然后还Documents/MyExcelsFolder通过另一个应用程序将新文件添加到了文件夹(例如FileManager

MyExcelsFolder然后我尝试从文件夹中获取所有文件

fun getAppFiles(context: Context): List<AppFile> {
        val appFiles = mutableListOf<AppFile>()

        val contentResolver = context.contentResolver
        val columns = mutableListOf(
            MediaStore.Images.Media._ID,
            MediaStore.Images.Media.DATA,
            MediaStore.Images.Media.DATE_ADDED,
            MediaStore.Images.Media.DISPLAY_NAME,
            MediaStore.Images.Media.MIME_TYPE
        ).apply {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                add(
                    MediaStore.MediaColumns.RELATIVE_PATH
                )
            }
        }.toTypedArray()
        val extensions = listOf("xls", "xlsx")
        val mimes = extensions.map { MimeTypeMap.getSingleton().getMimeTypeFromExtension(it) }

        val selection = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            "${MediaStore.MediaColumns.RELATIVE_PATH} LIKE ?"
        } else {
            "${MediaStore.Images.Media.DATA} LIKE ?"
        }

        val selectionArgs = arrayOf(
            "%${Environment.DIRECTORY_DOCUMENTS}/MyExcelsFolder%"
        ) …
Run Code Online (Sandbox Code Playgroud)

android uri file file-manager android-contentresolver

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

如何在AlertDialog.Builder AppCompat中更改Items的颜色?

如何在AlertDialog.Builder AppCompat中更改Items的颜色?

我想将textColor项目(照片,gallary)设置为其他任何项目.

这是我的代码:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
        builder.setTitle(getResources().getString(R.string.choose_image_source));
        builder.setItems(new CharSequence[]{getResources()
                        .getString(R.string.photo), getResources()
                        .getString(R.string.camera)}, new DialogInterface.OnClickListener() {
Run Code Online (Sandbox Code Playgroud)

...

<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">

        <item name="colorAccent">#000000</item><!-- buttons OK cancel-->
        <item name="android:textColorPrimary">#696969</item><!--text in message-->
        <item name="android:background">#f0a400</item> <!-- all bg-->
    </style>
    <style name="MyTitleTextStyle">
        <item name="android:textColor">#000000</item><!-- title color-->
        <item name="android:textAppearance">@style/TextAppearance.AppCompat.Title</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

android text colors android-appcompat android-alertdialog

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

显示在 SwitchCompat 上设置关闭状态下可见的文本?

目前我的SwitchCompat外观如下图(顶部),但是我需要在关闭状态下显示可见文本。

我将如何实现这一目标?

切换兼容图像


android switchcompat

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

许多重新连接后,onConnectionStateChange中的状态为GATT_FAILURE

我通过以下方式连接到ble设备:

 mBluetoothGatt = device.connectGatt(this.context, false, mGattCallback);
Run Code Online (Sandbox Code Playgroud)

然后

 mBluetoothGatt.disconnect();
Run Code Online (Sandbox Code Playgroud)

但如果我赶快做,然后我收到status=BluetoothGatt.GATT_FAILUREonConnectionStateChangemGattCallback

即使关闭/打开蓝牙,我也无法再次连接到GATT.

只有强制停止应用程序才能解决问题

android bluetooth bluetooth-lowenergy gatt

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

如何设置 SpannableStringBuilder 的重心?

我在一个 TextView 中使用了两种不同的字体:第一种是 SVG 字体,第二种是 TTF 字体。

要将带有文本的图标设置为 TextView,我正在使用它:

        String icon =getContext().getString(iconId);//"&#xF119;"
        String text = getResources().getString(labelId);//"AnyText"

        int iconLength = icon.length();
        String fulltext = icon + " " + text;
        SpannableStringBuilder spLabelWithIcon = new SpannableStringBuilder(fulltext);
        spLabelWithIcon.setSpan(new CustomTypefaceSpan(TypefaceManager.ICONS.getTypeface()),
                0, iconLength, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);

        spLabelWithIcon.setSpan(new CustomTypefaceSpan(TypefaceManager.GOTHAM_BOOK.getTypeface()),
                iconLength, fulltext.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);

myTextView.setText(spLabelWithIcon);
Run Code Online (Sandbox Code Playgroud)

结果:图标不在行的垂直中心(或者文本不在垂直中心):

在此处输入图片说明

android text spannable

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

如何停止 MediaBrowserServiceCompat?

我的服务:

public class MusicService extends MediaBrowserServiceCompat {
...
}
Run Code Online (Sandbox Code Playgroud)

我的活动:

public class MediaActivity extends AppCompatActivity{
private MediaBrowserCompat mMediaBrowser;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mMediaBrowser = new MediaBrowserCompat(this,
                new ComponentName(this, MusicService.class), mConnectionCallback, null);
        mMediaBrowser.connect();
}

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMediaBrowser.disconnect();
    }
Run Code Online (Sandbox Code Playgroud)

我想在 UI 中添加关闭按钮,但如何停止MusicService?它继续在后台进行投射。

android android-mediaplayer mediabrowserservice mediabrowserservicecompat mediabrowser

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

使用task.getByName找不到名称为名称的任务

我想按任务顺序创建任务

task fabricUploadDebug(type: Exec) {
dependsOn 'clean'
dependsOn 'compileDebugSources'
dependsOn 'assembleDebug'
dependsOn 'installDebug'
dependsOn 'crashlyticsUploadDistributionDebug'
tasks.getByName('compileDebugSources').mustRunAfter('clean')
tasks.getByName('assembleDebug').mustRunAfter('compileDebugSources')
tasks.getByName('installDebug').mustRunAfter('assembleDebug')
tasks.getByName('crashlyticsUploadDistributionDebug').mustRunAfter('installDebug')}
Run Code Online (Sandbox Code Playgroud)

我正在尝试从右侧面板“ Gradle”运行任务,但是错误是

Gradle sync failed: Task with name 'compileDebugSources' not found in project ':app'. // // Consult IDE log for more details (Help | Show Log) (2s 87ms) (moments ago)
Run Code Online (Sandbox Code Playgroud)

这是关于 /sf/answers/2303659991/

UPDATE 我试图输出所有任务:

 for(item in tasks){
        println "group= "+item.group+" ,path= "+item.path
    }
Run Code Online (Sandbox Code Playgroud)

但是我只有这个:为什么我无法执行其他任务?

group= build ,path= :app:assemble
group= build ,path= :app:assembleAndroidTest
group= build ,path= :app:buildDependents
group= build ,path= :app:buildNeeded …
Run Code Online (Sandbox Code Playgroud)

android gradle build.gradle android-gradle-plugin

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

Facebook:客户端令牌必须嵌入您的客户端代码中

Facebook抛出温暖错误,如何解决?

GraphRequest: Starting with v13 of the SDK, a client token must be embedded in your client code before making Graph API calls. Visit https://developers.facebook.com/docs/android/getting-started#client-token to learn how to implement this change.
Run Code Online (Sandbox Code Playgroud)

我已经添加到清单中了

  <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />
Run Code Online (Sandbox Code Playgroud)

版本:

"com.facebook.android:facebook-android-sdk:12.1.0"
Run Code Online (Sandbox Code Playgroud)

android facebook

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