展会信息港展会大全

Android--ListView滚动条样式
来源:互联网   发布日期:2015-11-26 16:18:47   浏览:1911次  

导读:当ListView的记录超过4页时才会显示滑块樀愀瘀愀代码:[html]瀀愀挀欀愀最攀 com.example.test0123; 椀洀瀀漀爀琀 java.lang...

当ListView的记录超过4页时才会显示滑块

java代码:

[html]

package com.example.test0123;

import java.lang.reflect.Field;

import android.app.Activity;

import android.graphics.drawable.Drawable;

import android.os.Bundle;

import android.view.View;

import android.view.ViewGroup;

import android.widget.AbsListView;

import android.widget.BaseAdapter;

import android.widget.ListView;

import android.widget.TextView;

public class TestList extends Activity {

ListView lv;www.2cto.com

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.list);

lv = (ListView) findViewById(R.id.listView1);

lv.setAdapter(new ListAdapter());

try {

Field f = AbsListView.class.getDeclaredField("mFastScroller");

f.setAccessible(true);

Object o = f.get(lv);

f = f.getType().getDeclaredField("mThumbDrawable");

f.setAccessible(true);

Drawable drawable = (Drawable) f.get(o);

drawable = getResources().getDrawable(R.drawable.ic_launcher);

f.set(o, drawable);

} catch (Exception e) {

throw new RuntimeException(e);

}

}

public class ListAdapter extends BaseAdapter {

public int getCount() {

return 200;

}

public Object getItem(int position) {

return null;

}

public long getItemId(int position) {

return 0;

}

public View getView(int position, View convertView, ViewGroup parent) {

TextView tv = new TextView(TestList.this);

tv.setTextSize(30);

tv.setText("aaaaa" + position);

return tv;

}

}

}

list.xml代码:设置fastScrollEnabled为true

[html]

<?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"

android:orientation="vertical" >

<ListView

android:id="@+id/listView1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:fastScrollEnabled="true"

>

</ListView>

</LinearLayout>

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港