LyricView 是一个强大而灵活的自定义视图,可在 Android 的音乐播放器中显示歌词。
LyricView 是一个功能强大且灵活的自定义视图,用于在 Android 系统下的音乐播放器中显示歌词。
//step 1//step 2
LyricView mLyricView = (LyricView)findViewById(R.id.custom_lyric_view);
//step 3
mLyricView.setLyricFile(lyricFile);
//step 4, 更新 LyricView 每隔一段时间
mLyricView.setCurrentTimeMillis(progress);
//step 5, 实现用户拖动歌词和点击播放图标时的接口
mLyricView.setOnPlayerClickListener(new LyricView.OnPlayerClickListener() {
@Override
public void onPlayerClicked(long progress, String content) {
}
});
| 属性 | 格式 | 默认值 | 说明 |
|---|---|---|---|
| fadeInFadeOut | boolean | false | 是否启用歌词淡入淡出 |
| hint | string | No Lyrics | 当不存在歌词文件时显示的提示信息 |
| hintColor | color | #FFFFFF |
提示文本的颜色 |
| textSize | dimension | 16sp | 歌词的文本大小 |
| textColor | color | #8D8D8D |
歌词的颜色 |
| highlightColor | color | #FFFFFF |
正在播放的当前歌词的颜色 |
| textAlign | enum | CENTER | 歌词的对齐方式 |
| maxLength | dimension | 300dp | 当歌词的宽度超过 maxLength 时换行 |
| lineSpace | dimension | 25dp | 行间距 |
| 方法 | 说明 |
|---|---|
setOnPlayerClickListener(OnPlayerClickListener listener) |
点击播放图标时的回调 |
setAlignment(@Alignment int alignment) |
设置歌词的对齐方式 |
setCurrentTimeMillis(long current) |
将歌词滚动到指定的时间毫秒 |
setLyricFile(File file) |
设置歌词文件,并通过 juniversalchardet-1.0.3 自动设置字符集 |
setLyricFile(File file, String charset) |
使用指定的字符集设置歌词文件 |
setTypeface(Typeface typeface) |
设置歌词的字体 |
reset() |
重置 |
[LyricViewDemo.apk][1] [YouTube][2]
暂无开放 Issues,或尚未同步最近议题。