Tag: anko

Bug – 无法更改supportActionBar标题

我试图从网络回调中调用的方法更改supportActionBar标题。 即使我从主线内部调用它,标题不会改变! 如果我尝试使用其他方法。 我的布局: <android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="@dimen/app_bar_height" android:fitsSystemWindows="true" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <ImageView android:id="@+id/userProfile" android:layout_width="match_parent" android:layout_height="match_parent" android:contentDescription="@string/str_act_main_user_list_item_user_profile_picture" /> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> 主要活动: class ActivityMain : BaseActivity(), ContractMainView { @Inject lateinit var mPresenter: ContractMainPresenter private var mUser: User? = null override fun onCreate(savedInstanceState: Bundle?) { […]

Anko忽略了在样式中定义的layout_margin

我创建了一个自定义样式: <style name="Static"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:layout_marginEnd">5dp</item> </style> 然后我用一个静态函数扩展了anko: inline fun ViewManager.static(theme: Int = R.style.Static, init: TextView.() -> Unit) = ankoView(::TextView, theme, init) 当我在我的布局中使用这个: static { text = resources.getString(R.string.name) } marginEnd值被忽略。 如果我在anko中手动添加边距: static { text = resources.getString(R.string.name) }.lparams { marginEnd = dip(5) } 保证金很好。 你们知道anko正在忽略我的保证金价值或其他方式为扩展视图anko函数定义一个预定义的保证金吗?

anko值用rxAndroid初始化

我想editText'B'从'A'获取文本时,'A'文本更改与安科 所以我使用Rxandroid获得了两个编辑文本值 val A = editText { textChangedListener { addTextinB(this@editText,B) } } val B = editText { hint = "should be changed " } fun addTextinB(v: EditText, v2:EditText) { RxTextView.afterTextChangeEvents(v) .debounce(50, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribe { tvChangeEvent -> v2.setText(tvChangeEvent.view().text) } 但是当我运行时,我看到“属性B应该得到之前被初始化”我认为B应该在调用addTextinB之前初始化,所以我改变了。 var A by Delegates.notNull<EditText>() var B by Delegates.notNull<EditText>() override fun onCreateView(){ //anko Code here … […]

Anko相当于xml中的样式属性

我需要创建无边界按钮。 在XML中最简单的方法来设置Widget.AppCompat.Button.Borderless 。 我试图用Anko做这个 button(theme = R.style.Widget_AppCompat_Button_Borderless_Colored, text = "Send") { horizontalGravity = Gravity.END lparams(wrapContent, wrapContent) } 但是没有效果。 我究竟做错了什么?

Anko日志与详细和调试不起作用

我正在尝试使用Anko Commons – Logging 但由于某种原因,详细和调试不显示在logcat上 但是,当我使用Log.d它按预期工作。 当我试着这个代码 verbose("————-verbose————–") debug("————-debug————–") info("————-info————–") warn("————-warn————–") error("————-error————–") wtf("————-wtf————–") 日志logcat如下 我正在使用安科0.10.0安卓工作室3.0加那利-5 当我试图寻找一个解决方案,我发现这一个 所有的Log。*都会记录到logcat,而不管当前的日志级别是什么。 但是,当日志级别可记录时,AnkoLogger。*将仅记录到logcat。 但是我不知道如何改变日志级别,如果连我的问题都是一样的。

Anko对话框按钮标题

与安科我可以写这样的东西显示对话框: alert("Dialog title") { yesButton {} noButton {} }.show() 我如何设置按钮的标题? noButton {title = "title"} 不起作用。

使用Anko添加/查询/解析SQLite

tl; dr:我有问题试图让我的代码工作,现在我可以使用Anko创建数据库并插入列,但是当我尝试插入数据,当我在sqliteman上打开数据库时,我的列是空的也不知道如何检索字符串/ Int中的数据发送到一个View 这显然工作正常,我可以看到我的数据库与正确的名称所有列创建 class MySqlHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "db_main") { companion object { private var instance: MySqlHelper? = null @Synchronized fun getInstance(ctx: Context): MySqlHelper { if (instance == null) { instance = MySqlHelper(ctx.applicationContext) } return instance!! } } override fun onCreate(db: SQLiteDatabase) { db.createTable("db_main", true, "_id" to INTEGER + PRIMARY_KEY + AUTOINCREMENT + NOT_NULL, […]

Anko日志记录方法无法解决

我试图抓住安科,碰到这个问题。 在它的文档说,Anko有一个便捷的日志记录方法 ,我试过了,但Android Studio不会自动导入它,所以我手动导入它,就像你在屏幕截图中看到的那样。 但是它仍然被标记为未解决。 这是我的gradle依赖关系: dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' compile 'com.android.support:support-v4:23.1.1' compile 'com.firebase:firebase-client-android:2.5.2' compile 'org.jetbrains.anko:anko-sdk15:0.8.2' compile 'org.jetbrains.anko:anko-support-v4:0.8' compile 'org.jetbrains.anko:anko-appcompat-v7:0.8' }

如何使用Anko DSL设置NavigationView的headerView?

在一般的XML布局中,默认的主布局是这样的: <?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> 我试图用Anko DSL编码: … override fun createView(ui: AnkoContext<MainActivity>) = with(ui) { drawerLayout { lparams(width = matchParent, height = matchParent) id = ID_DRAWER_LAYOUT fitsSystemWindows = true navigationView { lparams(width […]

如何引用Anko DSL中的其他视图?

我在我的Android项目中使用Anko,但我不知道如何引用我在DSL中创建的子视图,当引用的视图不在我参考它的同一级别。 以下代码工作: alert { customView { val input = textInputLayout { editText { hint = "Name" textColor =resources.getColor(R.color.highlight) } } positiveButton("OK") { "${input.editText.text}" } } }.show() 但下面的代码不起作用: alert { customView { val vertical = verticalLayout { textView { text = "Edit device name" textColor = resources.getColor(R.color.highlight) textSize = 24F } val input = textInputLayout { […]