安卓學習筆記 view,drawable

2021-10-12 12:28:52 字數 698 閱讀 6973

view

通過viewgroup.findviewbyid(r.id.view)繫結布局後,再將其他控制項(如button)載入到上下文後,通過viewgroup.addview(button) 在view中新增此控制項,**示例如下:

*viewgroup viewgroup = findviewbyid(r.id.activity_main6);

button button = (button) layoutinflater.from(this).inflate(r.layout.button,null);

viewgroup.addview(button);*

drawable

在res/drawable檔案中建立xml檔案,例如shape.xml,在view裡可將控制項的background設為shape,即可實現對控制項形狀顏色的自定義。

示例如下:

shape檔案

用法:
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margintop="20dp"

android:background="@drawable/shape1"

安卓學習筆記二

1 安卓intent啟動系統activity 1 啟動瀏覽器 intent intent new intent intent.setaction intent.action view uri url uri.parse intent.setdata url startactivity intent ...

安卓開發學習筆記

android設定背景色為透明 方法一 只要在配置檔案內activity屬性配置內加上 android theme android style theme.translucent 就好了。這樣就呼叫了android的透明樣式!方法二 先在res values下建colors.xml檔案,寫入 這個值...

安卓開發 學習筆記

setcontentview r.layout.activity main 這裡activity main為指定布局檔案 activity main.xml 在r所對應的變數,載入布局檔案,並顯示到視窗中。注 這裡布局檔案都在res資源目錄下 關於尺寸 在布局檔案中,除了字型大小,其他的都以dp作為...