一,自定义listview,gridview,实现在scrollview中的滚动,重写onMeasure方法,使listview,gridview不能自身滑动
核心代码:
public class MyListView extends ListView{
public MyListView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MyListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
二、自定义弹出进度对话框progressdialog
核心代码:
public static CustomProgressDialog createDialog(Context context) {
mCustomProgressDialog = new CustomProgressDialog(context,
R.style.CustomProgressDialog);
mCustomProgressDialog.setContentView(R.layout.progressdialog_style);
mCustomProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
return mCustomProgressDialog;
}
//为dialog中的imageview添加帧动画
public void onWindowFocusChanged(boolean hasFocus) {
if (mCustomProgressDialog == null) {
return;
}
ImageView imageView = (ImageView) mCustomProgressDialog
.findViewById(R.id.image_loading_view);
AnimationDrawable animationDrawable = (AnimationDrawable) imageView
.getBackground();
animationDrawable.start();
}
public CustomProgressDialog setMessage(String strMessage) {
TextView tvMsg = (TextView) mCustomProgressDialog
.findViewById(R.id.text_loading_msg);
if (tvMsg != null) {
tvMsg.setText(strMessage);
}
return mCustomProgressDialog;
}
三、自定义进度条progressbar
更改进度条的背景:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/progress_bg_holo_dark"
>
</item>
<item android:id="@android:id/secondaryProgress">
<clip android:drawable="@drawable/progress_secondary_holo_dark"/>
</item>
<item android:id="@android:id/progress"
>
<clip android:drawable="@drawable/progress_primary_holo_dark">
</clip>
</item>
</layer-list>
更改thumb的样式:
<!-- 按下状态 -->
<item
android:state_pressed="true"
android:drawable="@drawable/seek_thumb" />
<!-- 普通无焦点状态 -->
<item
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/seek_thumb" />
四、自定义notifycation通知栏
核心代码:
//设置RemoteViews内容,layoutId自己定义
remoteViews=new RemoteViews(activity.getPackageName(),R.layout.music_notification);
//点击通知返回主界面,通过隐式intent给通知栏中的view添加单击事件
Intent intentBack=new Intent(activity,MainActivity.class);
PendingIntent pIntent=PendingIntent.getActivity(activity, 0, intentBack, 0);
remoteViews.setOnClickPendingIntent(R.id.song_pic, pIntent);
builder.setContent(remoteViews);
builder.setSmallIcon(R.drawable.app_icon);
builder.setTicker("简单云音乐正在播放");
Notification mNotification=builder.build();
//获得完整的通知栏布局(没有这行代码,通知栏显示的是Android默认的高度,加载不完整)
mNotification.bigContentView=remoteViews;
nManager.notify(0, mNotification);