小编use*_*886的帖子

将BottomSheetDialogFragment的状态设置为展开

如何使用Android支持设计库(v23.2.1)将片段的状态设置为扩展BottomSheetDialogFragment为扩展BottomSheetBehavior#setState(STATE_EXPANDED)

https://code.google.com/p/android/issues/detail?id=202396说:

底部工作表首先设置为STATE_COLLAPSED.如果要展开它,请调用BottomSheetBehavior#setState(STATE_EXPANDED).请注意,您无法在视图布局之前调用该方法.

建议的做法需要将第一膨胀的观点,但我不知道我怎么会设置BottomSheetBehaviour到片段(BottomSheetDialogFragment).

View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);  
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);  
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-support-library android-support-design

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

如何制作高度可变的CardViews的网格布局?

CardView在XML中定义了多个:

<android.support.v7.widget.CardView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    card_view:cardPreventCornerOverlap="false"
    card_view:cardCornerRadius="4dp">
    <LinearLayout
        android:layout_width="wrap_content"
        android:orientation="vertical"
        android:layout_height="wrap_content">
        <TextView
            android:textSize="@dimen/abc_text_size_title_material"
            android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

对于手机,我已经将多个包装CardView在垂直方向LinearLayout:

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

对于平板电脑,我想使用网格布局,类似于Material Design规范中使用的设计,请参见此处的图像.

ViewGroup制作网格布局最好用的是什么?这些卡的高度可变,并且具有静态内容.

GridLayout 不能使用,因为卡的高度可变.

android android-layout material-design

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

使用Android中的单独组件配置使用Dagger 2进行测试

Dagger 2 文档建议使用interfacefor ProductionComponent提供不同的测试和生产配置TestComponent,如下所示:

@Component(modules = {
  OAuthModule.class, // real auth
  FooServiceModule.class, // real backend
  OtherApplicationModule.class,
  /* … */ })
interface ProductionComponent {
  Server server();
}

@Component(modules = {
  FakeAuthModule.class, // fake auth
  FakeFooServiceModule.class, // fake backend
  OtherApplicationModule.class,
  /* … */})
interface TestComponent extends ProductionComponent {
  FakeAuthManager fakeAuthManager();
  FakeFooService fakeFooService();
}
Run Code Online (Sandbox Code Playgroud)

假设我们有一个Android活动(MyApp),它使用ProductionComponent:

public class MyApp extends Application {
    private ProductionComponent component;

    @Override public void onCreate() {
        super.onCreate(); …
Run Code Online (Sandbox Code Playgroud)

java android integration-testing dagger-2

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

向 UITextView 中的 NSMutableAttributedString 添加填充

如何添加填充到的子串UITextView即是NSMutableAttributedString(以黄色显示这里高亮显示)?

在此处输入图片说明

我目前有属性文本(图像 2),属性文本周围没有任何填充,但需要向它添加一些填充(图像 3),这只是突出显示文本周围的一些间距(不是整个UITextView.

这是一个特写比较NSMutableAttributedString有/无填充的方式(此填充不应用于未归属的文本的其余部分):

在此处输入图片说明

这是我目前从 中获取文本的方式UITextView(在找到要突出显示的文本范围并将属性文本存储在 中之后attributedText):

var highlightedText = NSMutableAttributedString(string: "this text is highlighted")
let highlightedRange = NSRange(location: 0, length: highlightedText.characters.count)

highlightedText.addAttribute(NSBackgroundColorAttributeName,
                             value: UIColor.yellow, range: highlightedRange)

attributedText.replaceCharacters(in: highlightedRange, with: highlightedText)
Run Code Online (Sandbox Code Playgroud)

uitextview ios

7
推荐指数
0
解决办法
1895
查看次数

CardView按钮和文本没有对齐

我在使用与文本开头对齐的按钮创建CardView时遇到问题:

有问题的CardView的屏幕截图

我正在遵循材料设计规范中为填充和文本大小设置的尺寸.这是我正在使用的XML:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="16dp"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:paddingTop="24dp"
            android:text="Title goes here"
            android:textColor="@color/primary_text_default_material_light"
            android:textSize="24sp" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="16dp"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:text="Subtitle here"
            android:textSize="14sp" />

        <Button
            style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            android:padding="0dp"
            android:text="Action 1"
            android:textColor="@color/accent_material_light" />
    </LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

在视觉上,文本的开头和无边框按钮文本之间存在差距.

在此输入图像描述

材料设计规范中所示,按钮以及标题和副标题的开头应排成一行:

显示对齐的文本和按钮的材料设计cardview

我哪里错了?

android material-design

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

允许在UITextView中的任何位置选择光标

我有一个UITextView,它可以让你写多行文字.

如何让用户在没有长按的情况下在单词之间选择字母?

目前,当使用触摸屏选择单词之间的字符时,光标可以是单词的开头或结尾:

示例:单击"c"将光标移动到单词的结尾

光标在最后

示例:单击"a"将光标移动到单词的开头

光标在开始

所需的游标行为:选择文本中的任何位置 在此输入图像描述

允许在任何地方进行文本选择的功能(没有长按+放大镜)可以在iOS的许多代码编辑器应用程序中找到,例如CodaPythonista.

uitextview ios

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

在UINavigationController中控制向后滑动操作

我正在创建一个简单的闪存卡应用程序,如下图所示:

闪存卡没有动画

我想要向后滑动,就像这样:

闪存卡动画

要做到这一点,onBack(index: Int)我需要在刷卡时调用(为了更新显示的卡):

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var flashCardLabel: UILabel!

    // Populate initial content
    let content = ["Lorem", "Ipsum", "Dolor", "Sit"]

    // Index of where we are in content
    var index = 0

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    // Label text based on index
    func setLabelToIndex() {
        flashCardLabel.text = content[index]
    }

    // Go back
    @IBAction func back(_ sender: Any) {
        if index > 0 {
            index = index - 1
            setLabelToIndex()
        } …
Run Code Online (Sandbox Code Playgroud)

uiscrollview uinavigationcontroller ios swift

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

向每个WKWebView加载添加唯一的完成处理程序

我有使用加载多个网页的代码WKWebView。有没有一种方法可以将唯一的完成处理程序函数附加到每个WKWebView.loadHTMLString调用。

我注意到了每个返回值WKNavigation?,但是我不想使用它,WKNavigationDelegate因为它用于所有加载事件。

例如,现在没有完成处理程序,我这样做:

wkWebView?.loadHTMLString("<p>Loading page #1</p>", baseURL: nil)
Run Code Online (Sandbox Code Playgroud)

我想要一个像这样的独特完成处理程序:

wkWebView?.loadHTMLString("<p>SLoading page #1</p>", baseURL: nil, completionHandler: {
    print("Loaded page #1. Doing things only required for page #1.")
})
Run Code Online (Sandbox Code Playgroud)

然后对于不同的负载,我可以更改完成处理程序:

wkWebView?.loadHTMLString("<p>SLoading page #2</p>", baseURL: nil, completionHandler: {
    print("Loaded page #2")
})
Run Code Online (Sandbox Code Playgroud)

ios swift wkwebview

3
推荐指数
1
解决办法
1164
查看次数