小编azi*_*ian的帖子

使FAB不会被夹在底部导航栏中

我正在尝试将底部导航栏与FAB重叠。我希望我的导航栏看起来像这样:

所需结果

但是相反,它像这样切断了按钮:

当前结果

如何防止FAB被切断?这是我的XML:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.mobgen.designsprintapp.ui.main.MainActivity">

    <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:orientation="vertical">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            android:background="?android:attr/windowBackground"
            android:backgroundTint="@color/colorPrimary"
            app:itemBackground="@color/colorPrimary"
            app:itemIconTint="@color/nav_item_color_state"
            app:itemTextColor="@android:color/black"
            app:menu="@menu/navigation" >

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/tools"
                android:layout_width="56dp"
                android:layout_height="56dp"
                android:layout_gravity="center"
                android:layout_marginBottom="8dp"
                android:elevation="6dp"
                android:scaleType="center"
                app:srcCompat="@drawable/play" />
            </android.support.design.widget.BottomNavigationView>
    </LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

xml android android-layout android-view floating-action-button

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

Dagger2-DoubleCheck中的重复实例

我将Dagger v2.12与dagger-android-support以下配置一起使用:

AppComponent

@Singleton
@Component(
        modules = arrayOf(
                AndroidSupportInjectionModule::class,
                AndroidBindingModule::class,
                AppModule::class
        )
)
interface AppComponent : AndroidInjector<App> {
    @Component.Builder
    abstract class Builder : AndroidInjector.Builder<App>()
}
Run Code Online (Sandbox Code Playgroud)

AndroidBindingModule

@Module
abstract class AndroidBindingModule {
    @PerActivity
    @ContributesAndroidInjector(modules = arrayOf(MainModule::class))
    internal abstract fun contributeMainActivityInjector(): MainActivity
}
Run Code Online (Sandbox Code Playgroud)

主模块

@Module
class MainModule {

    ...

    @Provides @PerActivity
    fun providePresenter(rxLifecycle: ReactiveLifecycle, view: MainView) =
            MainPresenter(rxLifecycle, view)

}
Run Code Online (Sandbox Code Playgroud)

主要活动

class MainActivity : BaseActivity() {
    @Inject
    lateinit var presenter: MainPresenter

    ...
}
Run Code Online (Sandbox Code Playgroud)

在分析内存转储时,我注意到MainPresenter该类已经创建了两次,其中一个在MainActivitydagger.internal.DoubleCheck(如预期的那样) …

android kotlin dagger dagger-2

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

Loader <Cursor>仅加载选定的行+下一行

活动A中,我正在加载一个包含我表中所有值的列表,并设置了一个setOnItemClickListener来启动活动B并通过发送数据发送带有所选项的id [ 1 ] 的uri

[ 1 ] Uri currentTestUri = ContentUris.withAppendedId(TestEntry.CONTENT_URI, id);

活动B中,我的onCreateLoader包含投影:

String[] projection = {
       TestEntry._ID,
       TestEntry.COLUMN_TEST_ONE,
       TestEntry.COLUMN_TEST_TWO}
Run Code Online (Sandbox Code Playgroud)

...带有return语句

return new CursorLoader(this,  
    mCurrentTestUri, //Got this from Activity A         
    projection,             
    null,                   
    null,                   
    null);  
Run Code Online (Sandbox Code Playgroud)

我的onLoadFinished看起来像这样:

if (cursor.moveToFirst()) {
      int oneColumnIndex = cursor.getColumnIndex(TestEntry.COLUMN_TEST_ONE);
      int twoColumnIndex = cursor.getColumnIndex(TestEntry.COLUMN_TEST_TWO);

      String currentOne = cursor.getString(oneColumnIndex);
      String currentTwo = cursor.getString(twoColumnIndex);

      textViewOne.setText(currentOne);
      textViewTwo.setText(currentTwo);
}
Run Code Online (Sandbox Code Playgroud)

到目前为止一切顺利,现在我希望显示下一行(右下方)的值,但是使用不同的投影(我只需要_IDCOLUMN_TEST_ONE)并且onLoadFinished显示COLUMN_TEST_ONE的值textViewThree.

[两行的值应该同时显示,而不是一个或另一个]

我可以使用[ …

sqlite android android-cursorloader android-loader android-sqlite

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

来自 Notification 的深层链接 - 如何通过 backstack 向上传递数据?

在我的应用程序中,用户可以选择一个类别,然后在该类别中选择一个项目以最终查看项目详细信息。标准/转发流程是:

SelectCategoryFragment-> SelectItemFragment->ViewItemDetailsFragment

在选择类别时,selectedCatId通过Bundlefrom SelectCategoryFragmentto传递SelectItemFragment

    NavController navController = Navigation.findNavController(v);
    Bundle args = new Bundle();
    args.putLong(SelectItemFragment.ARG_CATEGORY_ID, selectedCatId);
    navController.navigate(R.id.action_nav_categories_to_items, args);
Run Code Online (Sandbox Code Playgroud)

SelectItemFragment然后将使用该getArguments().getLong(ARG_CATEGORY_ID)值来查询和显示所选类别中的相应项目。

这很好用。但是我现在正在尝试在用户点击通知时实现深度链接,将他们直接跳转到ViewItemDetailsFragment一个可以将他们带到SelectItemFragment, then的后台堆栈SelectCategoryFragment

我的问题是,如上所述,SelectItemFragment取决于ARG_CATEGORY_ID传递给它的参数以检索/显示其数据。我已经阅读了深层链接嵌套导航图,但真的不知道如何通过ARG_CATEGORY_ID深层链接/反向堆栈。

当用户按回时,是否有一种整洁的方式可以将数据从 传递ViewItemDetailsFragmentSelectItemFragment

android android-architecture-components android-architecture-navigation android-deep-link android-navigation-graph

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

Android设计支持库:TabLayout标签文本为单行

我想将标签文本(最多8个字符)放在一行中

在此输入图像描述

我为TabLayout元素添加了自定义样式

<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
    <item name="tabTextAppearance">@style/MyCustomTabTextAppearance</item>
</style>
<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="android:maxLines">1</item>
    <item name="android:singleLine">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

仍然没有成功.我也试过了

 <android.support.design.widget.TabLayout
  app:tabTextAppearance="@style/MyCustomTabTextAppearance"
  ..
  ..
  />
Run Code Online (Sandbox Code Playgroud)

android android-layout android-view android-viewpager android-tablayout

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

如何在build.gradle中使用最终解析的applicationId

说我有以下build.gradle

android{
    defaultConfig{
        applicationId "com.example.base"
    }
    buildTypes{
        release{
            minifyEnabled true
        }
        debug{
            applicationIdSuffix ".dev"
            minifyEnabled false
        }
    }
    productFlavors{
        free{
            applicationId "com.example.free"
        }
        paid{
            applicationId "com.example.paid"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想将生成的应用程序ID添加到strings.xml,如下所示:

resValue "string", "app_package", applicationId
Run Code Online (Sandbox Code Playgroud)

因此,我可以targetPackage在首选项xml中定义的意图中使用此值

但是该值会根据我在该行中放置的内容而有所不同:

  • defaultConfig->“ com.example.base”(始终为基本ID,无用)
  • productFlavours.free->“ com.example.free”(问题是调试构建不会更改为“ com.example.free.dev”)
  • productFlavours->错误,无法构建
  • buildTypes.debug->错误,无法构建

通过使用applicationIdSuffix,我需要gradle才能解析最终的ID,然后才能使用它。我怎么做?

android gradle android-resources android-gradle-plugin android-flavors

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

只混淆一种味道

我将如何只混淆一种味道。

不幸的是,风格 2 依赖于一个模块(jar),它使用了一些重复的类,由于它的设置方式,我无法混淆它。(第 3 方)所以希望跳过混淆味道。

我似乎无法在风味部分定义 minifyENabled false ,或将风味添加到构建部分。

请注意,实际上总共有 6 种口味。愿望是挑选应该混淆的口味

   buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors {
        flavour1{
            applicationId "uk.co.company.flavour1"
        }
        flavour2{
            applicationId "uk.co.company.flavour2"
        }
   }
Run Code Online (Sandbox Code Playgroud)

android proguard android-productflavors

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

PlaceAutocompleteFragment:自动打开SearchView

活动加载完成后,我想自动单击片段。

片段定义为:

 <fragment
    android:id="@+id/place_autocomplete_fragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
    />
Run Code Online (Sandbox Code Playgroud)

我尝试这样做

fragment = findViewById(R.id.place_autocomplete_fragment);

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            fragment.performClick();
        }
    }, 1000);
Run Code Online (Sandbox Code Playgroud)

但是没有用。

有什么方法可以自动单击片段吗?

编辑:就我而言,该片段由

//PlaceAutoComplete Search Implementation
    PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);


    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            Log.i(String.valueOf(this), "Place: " + place.getName() + "\nID: " + place.getId());
            String placeId = place.getId();
            try {
                Intent intent = new Intent(PlaceSearch.this, PlaceDetailsFromSearch.class);
                Bundle extras = new Bundle();
                extras.putString("placeID", placeId);
                intent.putExtras(extras);
                startActivity(intent);
            } catch (Exception e) …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-fragments android-view google-places

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

为什么我们使用ViewTreeObserver#addOnGlobalLayoutListener()

我们为什么使用ViewTreeObserver,任何人都可以解释一下?

在下面的代码creditsViewTextView对象。通过整个代码,我了解到“这是根据条件隐藏一些文本”,但是唯一的原因就是我们为什么要使用它ViewTreeObserver

mainLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            int heightDiff = mainLayout.getRootView().getHeight() - mainLayout.getHeight();

            if (heightDiff > 100) {
                Utils.appLogger("MyActivity", "keyboard opened");
                creditsView.setVisibility(View.GONE);
            }

            if (heightDiff < 100) {
                Utils.appLogger("MyActivity", "keyboard closed");
                creditsView.setVisibility(View.VISIBLE);
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

java android android-layout android-view android-viewtreeobserver

4
推荐指数
2
解决办法
4946
查看次数

Dagger 2:在构造函数中注入一个接口

我正在尝试学习匕首2,但我对使用接口注入构造函数感到困惑.这是我的下面的代码:

MainActivity.java

public class MainActivity extends AppCompatActivity implements MainView {

    // this keyword of request dependency . At compiling process, dagger will look at all of these annotations
    //to create the exact dependency

    @Inject MainPresenter mainPresenter ;
    TextView textView ;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = findViewById(R.id.textview) ;
        DaggerPresenterComponent.create().inject(this);
        textView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                mainPresenter.doThings(8555) ;
            }
        });

    }

    /**********************************/

    @Override
    public void invokeRandomViewMethod(String msg) {
        textView.setText(msg);
    }
}
Run Code Online (Sandbox Code Playgroud)

MainPresenter.java

public class …
Run Code Online (Sandbox Code Playgroud)

java android dependency-injection dagger dagger-2

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