我必須實現在我的項目中描述的活動欄。在android中顯示活動欄
http://developer.android.com/design/building-blocks/progress.html
如果有人知道如何做到這一點,請幫助我,我尋覓了很多的辦法做到這一點。
我必須實現在我的項目中描述的活動欄。在android中顯示活動欄
http://developer.android.com/design/building-blocks/progress.html
如果有人知道如何做到這一點,請幫助我,我尋覓了很多的辦法做到這一點。
MainActivity
public class MainActivity extends SherlockActivity {
private final Handler handler = new Handler();
private boolean useLogo = false;
private boolean showHomeUp = true;
ActionMode mMode;
Handler mHandler = new Handler();
Runnable mProgressRunner = new Runnable() {
@Override
public void run() {
mProgress += 2;
//Normalize our progress along the progress bar's scale
int progress = (Window.PROGRESS_END - Window.PROGRESS_START)/100 * mProgress;
setSupportProgress(progress);
if (mProgress < 100) {
mHandler.postDelayed(mProgressRunner, 50);
}
}
};
private int mProgress = 100;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
final ActionBar ab = getSupportActionBar();
// set defaults for logo & home up
ab.setDisplayHomeAsUpEnabled(showHomeUp);
ab.setDisplayUseLogoEnabled(useLogo);
((Button)findViewById(R.id.progress)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mProgress == 100) {
mProgress = 0;
mProgressRunner.run();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.main_menu, menu);
// set up a listener for the refresh item
final MenuItem refresh = (MenuItem) menu.findItem(R.id.menu_refresh);
refresh.setOnMenuItemClickListener(new OnMenuItemClickListener() {
// on selecting show progress spinner for 1s
public boolean onMenuItemClick(MenuItem item) {
// item.setActionView(R.layout.progress_action);
handler.postDelayed(new Runnable() {
public void run() {
refresh.setActionView(null);
}
}, 1000);
return false;
}
});
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// TODO handle clicking the app icon/logo
return false;
case R.id.menu_refresh:
// switch to a progress animation
item.setActionView(R.layout.indeterminate_progress_action);
return true;
default:
return super.onOptionsItemSelected(item);
}
}}
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Progress" />
</LinearLayout>
indeterminate_progress_action.xml
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:layout_marginLeft="@dimen/progress_action_padding"
android:layout_marginRight="@dimen/progress_action_padding" />
菜單/ main_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_refresh" android:showAsAction="ifRoom"
android:title="@string/action_label_refresh"
android:icon="@drawable/ic_menu_refresh_holo_dark" />
</menu>
AndroidManifest.xml中
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbarstyleexample"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="19" />
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme">
<activity android:name="com.actionbarsherlock.sample.styled.MainActivity"
android:label="@string/activity_name"
android:logo="@drawable/ad_logo"
android:uiOptions="splitActionBarWhenNarrow">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
使用進度與你的動作條或actionbarsherlock如果使用版本低於11 ... – Ranjit
我想實現的提醒that.thanks。 – Sunny