在android studio 3.0 canary 4 ui预览中丢失的类

我得到了我的XML预览器中缺少类的错误。 所以我不能在预览中看到我的布局,但是当我运行应用程序时,我可以看到一切正常。

这些类是在我的android studio项目中的一个模块内,并包含如下:

dependencies { compile project(":styleguide") } 

并用于这样的XML:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="64dp" android:orientation="vertical"> <com.company.packagename.buttons.SecondaryButtonLink android:layout_height="wrap_content" android:layout_width="match_parent"/> </LinearLayout> 

按钮看起来像这样:

 <merge xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/base_secondary_button_link_ll" android:layout_width="match_parent" android:layout_height="@dimen/button_height" android:clickable="true" style="@style/SelectableItemBackground" android:orientation="horizontal"> <com.company.packagename.textviews.LabelTextView android:id="@+id/secondary_button_link_title_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:textColor="@drawable/selector_secondary_button_link" android:drawableRight="@drawable/arrow_light_blue" android:drawablePadding="@dimen/button_icon_left_margin"/> </merge> 

而按钮类背后的代码是这样的:

 class SecondaryButtonLink @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : LinearLayout(context, attrs, defStyleAttr) { init { initializeView(attrs) } private fun initializeView(attrs: AttributeSet?) { val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater inflater.inflate(R.layout.secondary_button_link, this) if (attrs == null) return checkForImage(attrs) val typedArray = context.obtainStyledAttributes(attrs, R.styleable.StyleGuideButton) if (typedArray.hasValue(R.styleable.StyleGuideButton_title)) { setButtonTitle(typedArray) } } private fun setButtonTitle(typedArray: TypedArray) { for (i in 0..typedArray.indexCount - 1) { val attr = typedArray.getIndex(i) if (attr == R.styleable.StyleGuideButton_title) { secondary_button_link_title_tv.text = typedArray.getString(attr) } } } private fun checkForImage(attrs: AttributeSet){ val typedArray = context.obtainStyledAttributes(attrs, R.styleable.SecondaryButtonLink) if (typedArray.hasValue(R.styleable.SecondaryButtonLink_rightimage)) { setImage(typedArray) } } private fun setImage(typedArray: TypedArray){ for (i in 0..typedArray.indexCount - 1) { val attr = typedArray.getIndex(i) if (attr == R.styleable.SecondaryButtonLink_rightimage) { secondary_button_link_title_tv.setCompoundDrawablesWithIntrinsicBounds(null, null, typedArray.getDrawable(attr),null) } } } } 

我似乎无法指出为什么它不显示在预览器中。 有没有人有一个想法,为什么不显示?

它在Android工作室加那利4的错误,你只需要使用加那利1,直到他们修复它! 🙂