小编Nea*_*999的帖子

如何使用粗体字体创建自定义字体系列

我正在尝试使用此文档创建自定义字体系列https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html问题在于没有加粗属性和我不能以编程方式在XML中设置字体?

android

14
推荐指数
1
解决办法
3927
查看次数

在NestedScrollView中平滑滚动到Child

我在CardView父母的内部有可扩展的视图NestedScrollView.当扩展动画结束时,我正在尝试为子项创建平滑滚动.但我发现只有一个解决方案:

 scrollView.requestChildFocus(someView, someView);
Run Code Online (Sandbox Code Playgroud)

这段代码工作正常,但是,当requestChildFocus它调用时它立即滚动,这让我很烦恼.是否可以顺利滚动到孩子?

android nestedscrollview

13
推荐指数
2
解决办法
7616
查看次数

获取响应标头OkHttp

我需要检查HTTP request使用OkHTTP库的响应头.在加载数据之前,我需要检查它的最后更新时间.问题在于响应体是关于2 MB所以我需要只获得Last-Modified标题.是否可以仅加载没有响应主体的响应头,以提高程序的RESTful操作的速度?

java retrofit okhttp

8
推荐指数
2
解决办法
3493
查看次数

以编程方式约束布局

我正在尝试以ConstraintLayout编程方式添加视图。问题在于ConstraintLayout.LayoutParams忽略了MATCH_CONSTRAINT我的观点,而不是让最大宽度居中。

    TextView textView = new TextView(context);

    ConstraintLayout.LayoutParams lp = new ConstraintLayout.LayoutParams(MATCH_CONSTRAINT, WRAP_CONTENT);
    lp.leftToLeft = ConstraintLayout.LayoutParams.PARENT_ID;
    lp.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
    lp.rightToLeft = guideline.getId();
    lp.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;

    textView.setLayoutParams(lp);
    textView.setText("Title text");
    textView.setBackgroundColor(Color.BLUE);

    constraintLayout.addView(textView);
Run Code Online (Sandbox Code Playgroud)

android android-constraintlayout

8
推荐指数
1
解决办法
5705
查看次数

默认情况下折叠折叠工具栏

我有问题CollapsingToolbar.问题在于,默认情况下我需要在创建Activity时折叠工具栏.如果我通过appBarLayout.setExpanded(false, false)in onCreate()方法中的代码执行此操作,我第一次看到扩展工具栏,然后在一秒钟内折叠.我需要删除它并立即显示折叠的工具栏.

UPD:

<android.support.design.widget.AppBarLayout
    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/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:fitsSystemWindows="true">

  <android.support.design.widget.CollapsingToolbarLayout
      android:id="@+id/collapsing_toolbar"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      app:contentScrim="@color/colorPrimary"
      app:expandedTitleMarginEnd="64dp"
      app:expandedTitleMarginStart="16dp"
      app:layout_scrollFlags="scroll|exitUntilCollapsed">

    <ImageView
        android:id="@+id/toolbar_image_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:fitsSystemWindows="true"
        tools:ignore="ContentDescription"/>

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="@android:color/transparent"
        app:layout_collapseMode="pin">
    </android.support.v7.widget.Toolbar>
  </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)

android android-collapsingtoolbarlayout

7
推荐指数
1
解决办法
5455
查看次数

Anko相当于xml中的样式attr

我需要创建无边框按钮.设置xml中最简单的方法Widget.AppCompat.Button.Borderless.我正在尝试这样做Anko

button(theme = R.style.Widget_AppCompat_Button_Borderless_Colored, text = "Send") {
    horizontalGravity = Gravity.END
    lparams(wrapContent, wrapContent)
}
Run Code Online (Sandbox Code Playgroud)

但是没有效果.我究竟做错了什么?

android kotlin anko

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

Dagger.android UserScope

我试图创建一个用户范围https://google.github.io/dagger/android我有@Singleton,@ActivityScope,@FragmentScope@UserScope.

AppComponent

@Singleton
@Component(
  modules = [
    AndroidSupportInjectionModule::class,
    ActivityBindingModule::class,
    AppModule::class,
    ApiModule::class
  ]
)
interface AppComponent {

  fun inject(application: Application)

  fun createUserComponent(): UserComponent.Builder

  @Component.Builder
  interface Builder {

    @BindsInstance
    fun application(app: Application): Builder

    fun apiModule(module: ApiModule): Builder

    fun build(): AppComponent
  }
}
Run Code Online (Sandbox Code Playgroud)

UserComponent:

@UserScope
@Subcomponent(
  modules = [UserModule::class]
)
interface UserComponent {

  @Subcomponent.Builder
  interface Builder {
    @BindsInstance
    fun user(user: User): Builder

    fun build(): UserComponent
  }
}
Run Code Online (Sandbox Code Playgroud)

UserModule:

@Module
class UserModule {

  @UserScope …
Run Code Online (Sandbox Code Playgroud)

android dagger

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

Android:使用 Spannable 将带有项目符号的文本放入 TextView

我需要用几种语言写一些文本。文本看起来像:

标题

另一个标题

项目符号的颜色与其他文本不同。

我听说过Spannablein Android,但不幸的是我只能使用spanwithfromendint 值。问题在于,在不同的语言中,我的单词会有不同的位置,因此可跨文本不适合我。你能帮我以简单的方式解决这个问题吗?

android textview spannablestring

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

使用 Git 进行 Gradle 版本控制

我正在尝试使用 Git 在 Gradle 中创建自动版本控制,但在构建应用程序时遇到一些错误。我的操作系统是Windows。

def getVerName = { ->
    try {
        def stdout = new ByteArrayOutputStream()
        exec {
            commandLine "git", "describe", "--long"
            standardOutput = stdout
        }
        def result = stdout.toString()
        result = result.trim()
        return result
    } catch (ignored) {
        return null
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的异常的堆栈跟踪

我的GIT路径:C:\Program Files\Git\cmd. 设置PATH局部变量什么也不做。从 StackTrace 中您可以看到 Gradle 正在应用程序目录中查找 git.exe。如何改变这条路径?

org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'git''
    at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:197)
    at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:327)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:86)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at …
Run Code Online (Sandbox Code Playgroud)

git android gradle

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

似乎是支持设计库中的一个错误

我正在尝试创建一个与Google Photosapp UI 类似的应用程序.支持Libary版本= 25.1.0.

半透明状态和导航栏的问题,内部的小部件CoorinatorLayout看起来并不像预期的那样.设置fitsSystemWindows=true属性BottomNavigationView使其太大(屏幕截图1),并且SnakBar在这种情况下出现在导航栏后面,而不是在BottomNavView预期的上方或导航栏.如果我添加fitsSystemWindows=trueToolbar(截图2),然后BottomNavigationView失去它的fitsSystemWindows属性和Toolbar内容的地方去了.它看起来像一个支持库错误,但我不确定.

这是我的DSL代码:

       coordinatorLayout {

                customToolbar {
                    id = TOOLBAR
//                  fitsSystemWindows = true
                    title = createTitle(ctx)
                    lparams(matchParent, dip(48))
                }

                frameLayout {
                    id = CONTENT_FRAME
                    backgroundResource = R.color.colorBackground
                    lparams(matchParent, matchParent)
                }

                bottomNavigationView(R.style.Base_ThemeOverlay_AppCompat_Dark) {
                    id = BOTTOM_NAVIGATION_VIEW

                    fitsSystemWindows = true
                    itemIconTintList = ContextCompat.getColorStateList(ctx, R.drawable.nav_item_color_state)
                    itemTextColor = ContextCompat.getColorStateList(ctx, R.drawable.nav_item_color_state)
                    backgroundResource = R.color.colorAccent
                    inflateMenu(R.menu.menu_drawer_2)
                    lparams(matchParent) {
                        anchorGravity = Gravity.BOTTOM …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-support-library anko android-support-design

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

如何从支持设计库向Nav Drawer添加计数器

我需要在NavigationDrawer的字段中添加一个计数器nav_films_been_wathced,但我找不到如何正确地执行此操作.我正在使用 com.android.support:design:23.0.1

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

我的menu.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group
        android:id="@+id/group_top"
        android:checkableBehavior="single">
        <item
            android:id="@+id/nav_main"
            android:icon="@drawable/ic_home"
            android:title="@string/nav_main" />
        <item
            android:id="@+id/nav_films_been_wathced"
            android:icon="@drawable/ic_films"
            android:title="@string/nav_films_been_wathced" />
    </group>

    <group
        android:id="@+id/group_bottom"
        android:checkableBehavior="none">
        <item
            android:id="@+id/nav_about"
            android:icon="@drawable/ic_info"
            android:title="@string/nav_about" />
    </group>

</menu>
Run Code Online (Sandbox Code Playgroud)

android navigation-drawer android-support-design

2
推荐指数
1
解决办法
1327
查看次数