1
目前,我正在使用Styles.xml與Java代碼結合來定義PullToRefresh自定義。我只想通過Java代碼來完成所有的定製,而不是用XML定義它們。我可以通過編程實現所有的自定義嗎?ActionBar - PullToRefresh以編程方式實現而不使用樣式
這裏是我的XML定製:
<!-- PullToRefresh Customizations -->
<style name="Theme.Holo.CustomPtrHeader" parent="Theme.Sherlock">
<item name="ptrHeaderStyle">@style/Widget.Custom.PtrHeader</item>
</style>
<style name="Widget.Custom.PtrHeader" parent="android:Widget">
<!-- The background of the header view -->
<item name="ptrHeaderBackground">#FF69B4</item>
<!-- Color to tint the progress bar -->
<item name="ptrProgressBarColor">#FF69B4</item>
<!-- The strings to be displayed at the various states -->
<item name="ptrPullText">Pull To Refresh</item>
<item name="ptrRefreshingText">Refreshing News</item>
<item name="ptrReleaseText">Loading...</item>
</style>
Java代碼:
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ViewGroup viewGroup = (ViewGroup) view;
mPullToRefreshLayout = new PullToRefreshLayout(activity);
ActionBarPullToRefresh
.from(activity)
.insertLayoutInto(viewGroup)
.theseChildrenArePullable(R.id.gridview_news_grid,
android.R.id.empty).listener(this)
.setup(mPullToRefreshLayout);
}
@Override
public void onRefreshStarted(View view) {
if (Const.DEBUGGING)
Log.d(Const.DEBUG, "PullToRefresh Started");
gridview.setVisibility(View.INVISIBLE);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
getDataFromServer();
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
mPullToRefreshLayout.setRefreshComplete();
if (getView() != null) {
gridview.setVisibility(View.VISIBLE);
}
}
}.execute();
}
我想我可以使用選項()這樣做的,但不知道如何正確地做到這一點。有人可以幫我解決這個問題。