如何使用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
我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
不能使用,因为卡的高度可变.
Dagger 2 文档建议使用interface
for 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) 如何添加填充到的子串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) 我在使用与文本开头对齐的按钮创建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)
在视觉上,文本的开头和无边框按钮文本之间存在差距.
如材料设计规范中所示,按钮以及标题和副标题的开头应排成一行:
我哪里错了?
我有一个UITextView
,它可以让你写多行文字.
如何让用户在没有长按的情况下在单词之间选择字母?
目前,当使用触摸屏选择单词之间的字符时,光标可以是单词的开头或结尾:
示例:单击"c"将光标移动到单词的结尾
示例:单击"a"将光标移动到单词的开头
允许在任何地方进行文本选择的功能(没有长按+放大镜)可以在iOS的许多代码编辑器应用程序中找到,例如Coda和Pythonista.
我正在创建一个简单的闪存卡应用程序,如下图所示:
我想要向后滑动,就像这样:
要做到这一点,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) 我有使用加载多个网页的代码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)