2
通常最好的學習研究工作的例子和星星點點 黑客在一起,直到我明白了一切是如何工作的。我沒有用ActionBars
或ABS
太多的經驗,但我發現的原生ActionBar
一個工作演示。我在這裏找到:https://github.com/johannilsson/android-actionbar轉換本地操作欄即可操作欄福爾摩斯
我得到了這個演示和ABS library
啓動和運行在日食。我現在的問題是我該如何將其轉換爲ABS動作條或者使用ABS重新創建等價物?(僅僅是一個簡單的起動器ABS動作條,我可以使用它來連接不同活動的幾個物品。)
這裏是操作欄演示代碼:
package com.markupartist.android.actionbar.example;
import com.markupartist.android.widget.ActionBar;
import com.markupartist.android.widget.ActionBar.Action;
import com.markupartist.android.widget.ActionBar.IntentAction;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class HomeActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
//actionBar.setHomeAction(new IntentAction(this, createIntent(this), R.drawable.ic_title_home_demo));
actionBar.setTitle("Home");
final Action shareAction = new IntentAction(this, createShareIntent(), R.drawable.ic_title_share_default);
actionBar.addAction(shareAction);
final Action otherAction = new IntentAction(this, new Intent(this, OtherActivity.class), R.drawable.ic_title_export_default);
actionBar.addAction(otherAction);
Button startProgress = (Button) findViewById(R.id.start_progress);
startProgress.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
actionBar.setProgressBarVisibility(View.VISIBLE);
}
});
Button stopProgress = (Button) findViewById(R.id.stop_progress);
stopProgress.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
actionBar.setProgressBarVisibility(View.GONE);
}
});
Button removeActions = (Button) findViewById(R.id.remove_actions);
removeActions.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
actionBar.removeAllActions();
}
});
Button addAction = (Button) findViewById(R.id.add_action);
addAction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
actionBar.addAction(new Action() {
@Override
public void performAction(View view) {
Toast.makeText(HomeActivity.this, "Added action.", Toast.LENGTH_SHORT).show();
}
@Override
public int getDrawable() {
return R.drawable.ic_title_share_default;
}
});
}
});
Button removeAction = (Button) findViewById(R.id.remove_action);
removeAction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
int actionCount = actionBar.getActionCount();
actionBar.removeActionAt(actionCount - 1);
Toast.makeText(HomeActivity.this, "Removed action." , Toast.LENGTH_SHORT).show();
}
});
Button removeShareAction = (Button) findViewById(R.id.remove_share_action);
removeShareAction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
actionBar.removeAction(shareAction);
}
});
}
public static Intent createIntent(Context context) {
Intent i = new Intent(context, HomeActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return i;
}
private Intent createShareIntent() {
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Shared from the ActionBar widget.");
return Intent.createChooser(intent, "Share");
}
}