實現(xiàn)下圖效果只需一個TextView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:drawableLeft="@drawable/icon_1"
android:drawableRight="@drawable/icon_4"
android:drawablePadding="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="16sp"
android:text="我的卡券"
android:background="@color/white"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="50dp" />
</LinearLayout>
動態(tài)設置文本與圖片相對位置時纸巷,常用到如下方法:
setCompoundDrawables(left, top, right, bottom)
setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)
兩者有些區(qū)別:setCompoundDrawables 畫的drawable的寬高是按drawable.setBound()設置的寬高,所以才有The Drawables must already have had setBounds(Rect) called.
使用之前必須使用Drawable.setBounds設置Drawable的長寬鸥拧。
setCompoundDrawablesWithIntrinsicBounds是畫的drawable的寬高是按drawable固定的寬高厕诡,所以才有The Drawables' bounds will be set to their intrinsic bounds.
即通過getIntrinsicWidth()與getIntrinsicHeight()獲得
LinearLayout添加分割線
LinearLayout有兩個屬性
1累榜、Android:divider="@drawable"
drawable可以是圖片文件,也可以是xml繪制的shape灵嫌。
使用shape的時候一定要添加<size> 壹罚,一定要添加顏色,即使是透明寿羞,例如:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/account_line" />
<size android:height="1px" />
</shape>
2猖凛、
android:showDividers = "middle|end|beginning|none"
middle 在每一項中間添加分割線
end 在整體的最后一項添加分割線
beginning 在整體的最上方添加分割線
none 無
使用.9圖
先將圖片名加上.9,如原圖名為ic_launcher.png绪穆,則改為ic_launcher.9.png
雙擊打開后點擊左下角
就可以使用了
EditText樣式
1.更改光標顏色:可設置顏色或圖片
android:textCursorDrawable="@color/colorPrimary"
android:backgroundTint="#9bd435" <!--下劃線顏色-->
android:textColorHighlight="#9bd435" <!--選中文字背景色-->
3.使用Material Design主題屬性
首先了解一下Material Design 各個屬性辨泳。這里有張在網(wǎng)上找來的圖,此圖一目了然玖院。
那么其實就簡單了菠红,在我們的主題中加入colorAccent
即可。
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">#9bd435</item>
</style>
效果圖: