2017-06-28 3 views
0

Ich bekomme den Fehler, dass Klassen in meinem XML-Previewer fehlen. Daher kann ich mein Layout in der Vorschau nicht sehen, aber wenn ich die App starte, kann ich alles gut sehen.Fehlende Klassen in Android Studio 3.0 Kanarienvogel 4 Vorschau

Die Klassen sind in einem Modul in meinem Android-Studio-Projekt und wie so enthalten:

dependencies { 
    compile project(":styleguide") 
} 

Und in der XML wie folgt verwendet:

<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> 

Und die Schaltfläche sieht wie folgt aus:

<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> 

Und der Code hinter der Schaltfläche Klasse ist wie folgt:

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) 
      } 
     } 
    } 
} 

Ich kann nicht feststellen, warum es in der Vorschau nicht angezeigt wird. Hat jemand eine Idee warum er nicht auftaucht?

Antwort

0

es ist ein Bug auf Android Studio Canary 4 Sie brauchen nur zu verwenden Canary 1, bis sie es beheben! :)

Verwandte Themen