0

此問題涉及Intellij IDEA 13或Android Studio上的Android開發。Android Studio,Intellij 13:在佈局預覽中使用Log.i

我創建了一個非常簡單的自定義視圖:

public class CustomView extends View{ 

    public CustomView(Context context, AttributeSet attrs) { 
     super(context, attrs); 

     Log.i("TAG", "Hello Preview!"); 
    } 
} 

我那麼它嵌入到一個佈局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <com.example.myapplication.app.CustomView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#FFFF00"/> 

</FrameLayout> 

我現在可以看到在佈局預覽窗口中的視圖:

enter image description here

如果我在設備或模擬器上運行應用程序,我wo希望看到文本「Hello Preview!」在logcat的窗口,但如果我使用預覽模式下,日誌爲空:

enter image description here

有沒有辦法從在預覽模式下運行的自定義視圖日誌輸出?我不想在設備或模擬器上運行應用程序,只是爲了查看視圖中的日誌輸出。

我不在乎解決方案是否涉及Log.i.你可以建議一些其他的日誌功能,甚至是一個自定義的插件或庫。

回答

1

沒有設備連接,因此沒有人向您發送Log.i。如果您在模擬器或手機上運行程序,輸出將會在那裏

+0

感謝您的回答。我瞭解日誌記錄如何在設備或模擬器上工作。我將編輯該問題以使其更清楚。 – SharkAlley

+0

好的,我編輯了一下以澄清問題。謝謝你的幫助。 – SharkAlley

+1

在這種情況下,我不知道。更簡單,打開模擬器... –

相關問題