下面列出了android.app.ActionBar#setBackgroundDrawable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void configureActionbar(){
ActionBar bar = getActionBar();
bar.setHomeButtonEnabled(true);
bar.setDisplayShowHomeEnabled(false);
tint = new SystemBarTintManager(this);
TypedValue tintColor = new TypedValue();
if(getTheme().resolveAttribute(R.attr.statusBarBackground, tintColor, true)){
tint.setStatusBarTintEnabled(true);
tint.setTintColor(tintColor.data);
defaultActionbarColor = tintColor.data;
currentActionbarColor = tintColor.data;
}else{
tint.setStatusBarTintEnabled(false);
}
TypedValue actionbarBackground = new TypedValue();
if(getTheme().resolveAttribute(R.attr.actionbarBackgroundLayerList, actionbarBackground, false)){
actionbarBackgroundList = (LayerDrawable) getResources().getDrawable(actionbarBackground.data);
actionbarBackgroundList.mutate();
actionbarColor = (ColorDrawable) actionbarBackgroundList.findDrawableByLayerId(R.id.actionbar_background_color);
actionbarColor.mutate();
bar.setBackgroundDrawable(actionbarBackgroundList);
}
}
@Override
public boolean updateStyle(List<PXRuleSet> ruleSets, List<PXStylerContext> contexts) {
// For the default case where we style just the action-bar, with no
// virtual child involved, we will generate and set a background
// drawable that will act as the default background.
if (!super.updateStyle(ruleSets, contexts)) {
return false;
}
PXStylerContext context = contexts.get(0);
ActionBar actionBar = (ActionBar) context.getStyleable();
// We just overwrite the exiting background. No states merging here.
RectF bounds = getBounds(actionBar);
actionBar.setBackgroundDrawable(PXDrawableUtil.createDrawable(bounds,
context.getCombinedPaints()));
return true;
}
@Override
public void onColorChanged(int color) {
if (color != mLastColor) {
mLastColor = color;
DUtils.log("setting: #" + Integer.toHexString(color));
boolean actionbar = true;
if (actionbar) {
ActionBar bar = getActivity().getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(color));
bar.setTitle(bar.getTitle());
} else {
getActivity().getWindow().setBackgroundDrawable(new ColorDrawable(color));
}
}
}
private void setupActionBarDrawable(Drawable drawable) {
if (drawable != null) {
ActionBar actionBar = LuaViewUtil.getActionBar(getGlobals());
if (actionBar != null) {
actionBar.setBackgroundDrawable(drawable);
}
}
}
public static void initActionBar(ActionBar actionBar, int newColor) {
Drawable colorDrawable = new ColorDrawable(newColor);
LayerDrawable ld = new LayerDrawable(new Drawable[]{colorDrawable});
if (actionBar != null) {
// System.out.println("action bar != null");
actionBar.setBackgroundDrawable(ld);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_new_post);
final ImageView userPicture = (ImageView) findViewById(R.id.cna_userPicture);
final TextView userName = (TextView) findViewById(R.id.cna_userDisplayName);
final MyUser[] loggedUser = {BaseViewModel.getInstance().getLoggedUser()};
if (loggedUser[0] == null) {
BaseViewModel.EverliveAPP.workWith().
users(MyUser.class).
getMe().
executeAsync(new RequestResultCallbackAction<MyUser>() {
@Override
public void invoke(RequestResult<MyUser> requestResult) {
if (requestResult.getSuccess()) {
loggedUser[0] = requestResult.getValue();
BaseViewModel.getInstance().setLoggedUser(loggedUser[0]);
loadUserInfo(userPicture, loggedUser[0], userName);
}
}
});
} else {
loadUserInfo(userPicture, loggedUser[0], userName);
}
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.argb(255, 52, 73, 94)));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Intialize and set the Action Bar to Holo Blue
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33b5e5" )));
GridView grid = (GridView) findViewById(R.id.myGrid);
rowItems = new ArrayList<RowItem>();
String[] titles = {"Movie1","Movie2","Movie3","Movie4","Movie5","Movie6","Movie7","Movie8"};
String[] descriptions = {"First Movie","Second movie","Third Movie","Fourth Movie","Fifth Movie",
"Sixth Movie","Seventh Movie","Eighth Movie"};
//Populate the List
for (int i = 0; i < titles.length; i++) {
RowItem item = new RowItem(images[i], titles[i], descriptions[i]);
rowItems.add(item);
}
// Set the adapter on the ListView
LazyAdapter adapter = new LazyAdapter(getApplicationContext(), R.layout.grid_row, rowItems);
grid.setAdapter(adapter);
grid.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.show();
actionBar.setTitle(null);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
interstitialFragment = new InterstitialFragment();
addFragment(interstitialFragment, InterstitialFragment.TAG);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.show();
actionBar.setTitle(null);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Intialize and set the Action Bar to Holo Blue
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33b5e5" )));
GridView grid = (GridView) findViewById(R.id.myGrid);
rowItems = new ArrayList<RowItem>();
String[] titles = {"Movie1","Movie2","Movie3","Movie4","Movie5","Movie6","Movie7","Movie8"};
String[] descriptions = {"First Movie","Second movie","Third Movie","Fourth Movie","Fifth Movie",
"Sixth Movie","Seventh Movie","Eighth Movie"};
//Populate the List
for (int i = 0; i < titles.length; i++) {
RowItem item = new RowItem(images[i], titles[i], descriptions[i]);
rowItems.add(item);
}
// Set the adapter on the ListView
LazyAdapter adapter = new LazyAdapter(getApplicationContext(), R.layout.grid_row, rowItems);
grid.setAdapter(adapter);
grid.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
}
});
}
@SuppressLint("NewApi")
private void initiateActionBar() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(res.getString(R.string.product_detail));
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33B5E5")));
}
}
/**
* Initiate actionbar.
*/
@SuppressLint("NewApi")
private void initiateActionBar() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(getResources().getString(R.string.sale));
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33B5E5")));
}
}
@SuppressLint("NewApi")
private void initiateActionBar() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(res.getString(R.string.product_detail));
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33B5E5")));
}
}
/**
* Initiate actionbar.
*/
@SuppressLint("NewApi")
private void initiateActionBar() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(getResources().getString(R.string.sale));
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33B5E5")));
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
Bitmap b = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
actionBar.
setBackgroundDrawable(new BitmapDrawable(getResources(), b));
// add the custom view to the action bar
actionBar.setCustomView(R.layout.actionbar_view);
EditText search = (EditText) actionBar.getCustomView().findViewById(
R.id.searchfield);
search.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
Toast.makeText(MainActivity.this, "Search triggered",
Toast.LENGTH_LONG).show();
return false;
}
});
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM
| ActionBar.DISPLAY_SHOW_HOME);
}
private void setupActionBarColor(ActionBar actionBar) {
appBarColor = getIntent().getIntExtra("appBarColor" , 0xFF424242);
actionBar.setBackgroundDrawable(new ColorDrawable(appBarColor));
actionBar.setDisplayHomeAsUpEnabled(true);
}