- TextView設(shè)置刪除線
mTvDemo.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
- TextView設(shè)置文本格式
mTvPay.setText(String.format(getString(R.string.price_format_pay), mPayDetail.price));
其中
<string name="price_format_pay">支付¥%1$s</string>
更多的格式岩饼,比如視頻播放時間:特殊符號用\轉(zhuǎn)義,02d表示接收的是數(shù)字,格式為兩位,不足的前面補0。這個格式接收兩個數(shù)字作為參數(shù)挺物,下面的設(shè)置會顯示03'19''
<string name="mv_video_time">%1$02d\'%2$02d\"</string>
mTvTime.setText(String.format(getString(R.string.mv_video_time), 3,19));
- 自定義帶二級進(jìn)度的seekbar樣式
效果圖:
- seekbar的xml
<SeekBar
android:id="@+id/sb_player_seek_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:maxHeight="3dp"
android:minHeight="3dp"
android:background="@null"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:progressDrawable="@drawable/seekbar_bkg"
android:thumb="@drawable/icon_play_seek_point"/>
icon_play_seek_point是一個進(jìn)度標(biāo)志的icon,android:maxHeight與android:minHeight控制進(jìn)度條的高度母债,這個不影響進(jìn)度icon的大小。
- 進(jìn)度相關(guān)的drawable:seekbar_bkg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@android:id/background"
android:drawable="@drawable/seekbar_progress_bkg"/>
<item android:id="@android:id/secondaryProgress">
<clip android:drawable="@drawable/seekbar_progress_second" />
</item>
<item android:id="@android:id/progress">
<clip android:drawable="@drawable/seekbar_progress_first" />
</item>
</layer-list>
- 各級背景的xml:
3.1 seekbar_progress_bkg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<stroke android:width="3dp" android:color="@color/global_ffe0e0e0" />
</shape>
3.2 seekbar_progress_first.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<stroke android:width="3dp" android:color="@color/global_ffff4338" />
</shape>
3.3 seekbar_progress_second.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<stroke android:width="3dp" android:color="@color/global_ffe0e0e0" />
</shape>
3.4 取消seekbar的點擊和滑動功能尝抖,只作為展示用
mSeekBar.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// 禁止拖動和點擊
return true;
}
});
- 設(shè)計說要加上圓角毡们,正好精簡一下:
- 直接用一個樣式搞定,seekbar_bkg_two_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background">
<shape>
<solid android:color="@color/global_ffe0e0e0"/>
<corners android:radius="4dp"/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<solid android:color="@color/global_ff666666" />
<corners android:radius="4dp"/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="@color/global_ffff4338" />
<corners android:radius="4dp"/>
</shape>
</clip>
</item>
</layer-list>
- 定義一個style用于格式通用:
<style name="mv_video_play_seekbar">
<item name="android:maxHeight">3dp</item>
<item name="android:minHeight">3dp</item>
<item name="android:max">100</item>
<item name="android:background">@null</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">8dp</item>
<item name="android:layout_marginLeft">3dp</item>
<item name="android:layout_marginRight">3dp</item>
<item name="android:thumbOffset">8dp</item>
<item name="android:progressDrawable">@drawable/seekbar_bkg_two_progress</item>
<item name="android:thumb">@drawable/icon_play_seek_point</item>
</style>
- 關(guān)于Activity主題的問題:
系統(tǒng)SeekBar的thumb用的帶陰影的png昧辽,當(dāng)Activity時非透明的主題時衙熔,盡管邊界為透明,陰影還是會影響顯示搅荞,圓形兩側(cè)有縫隙:
所以用帶陰影的切圖的話红氯,上下可以有透明陰影,兩端不能有投影咕痛,要緊貼圓形的左右邊界痢甘,都是因為沒有仔細(xì)想,只是一味的看現(xiàn)象改代碼暇检。最后产阱,用layer-list代碼創(chuàng)造陰影:
style中改為:
<item name="android:thumb">@drawable/seek_bar_thumb_shadow</item>
其中seek_bar_thumb_shadow.xml為
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background">
<shape>
<solid android:color="@color/global_ffe0e0e0"/>
<corners android:radius="4dp"/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<solid android:color="@color/global_ff666666" />
<corners android:radius="4dp"/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="@color/global_ffff4338" />
<corners android:radius="4dp"/>
</shape>
</clip>
</item>
</layer-list>
一個簡單的樣式,如此多細(xì)節(jié)块仆,關(guān)鍵是沒有真正弄明白各種樣式构蹬,主題和作用機制,面向運氣編程果真不靠譜盎诰荨庄敛!
所以,去自定義吧