本文整理匯總了Java中android.widget.Button.setBackgroundColor方法的典型用法代碼示例。如果您正苦於以下問題:Java Button.setBackgroundColor方法的具體用法?Java Button.setBackgroundColor怎麽用?Java Button.setBackgroundColor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.Button
的用法示例。
在下文中一共展示了Button.setBackgroundColor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: showCorrectOptions
import android.widget.Button; //導入方法依賴的package包/類
private void showCorrectOptions() {
for (int i = 0; i < 3; i++) {
Option option = mQuestion.getOptionList().get(i);
Button button = null;
switch (i) {
case 0:
button = mOption1Button;
break;
case 1:
button = mOption2Button;
break;
case 2:
button = mOption3Button;
break;
}
if (button != null) {
if (option.isCorrect()) {
button.setBackgroundColor(Color.GREEN);
} else {
button.setBackgroundColor(Color.RED);
}
}
}
}
示例2: showCorrectOptions
import android.widget.Button; //導入方法依賴的package包/類
private void showCorrectOptions() {
mQuestionCardData.mShowCorrectOptions = true;
for (int i = 0; i < 3; i++) {
Option option = mQuestionCardData.options.get(i);
Button button = null;
switch (i) {
case 0:
button = mOption1Button;
break;
case 1:
button = mOption2Button;
break;
case 2:
button = mOption3Button;
break;
}
if (button != null) {
if (option.isCorrect) {
button.setBackgroundColor(Color.GREEN);
} else {
button.setBackgroundColor(Color.RED);
}
}
}
}
示例3: cancel
import android.widget.Button; //導入方法依賴的package包/類
public void cancel(View view) {
if (null != mCurrentLocation) {
String lat = String.valueOf(mCurrentLocation.getLatitude());
String lng = String.valueOf(mCurrentLocation.getLongitude());
if (checkBusSelection != 0) {
//String BUS = "b" + checkBusSelection;
DatabaseReference userDatabase = mDatabase.child(VEHICLE).child(BUS);
//String key = userDatabase.push().getKey();
userDatabase.child(key).removeValue();
Toast.makeText(MapsActivity.this, "REQUEST ENDED", Toast.LENGTH_LONG).show();
Button button = (Button) findViewById(R.id.pick_me);
button.setClickable(true);
button.setBackgroundColor(Color.BLUE);
}
} else {
Log.d(TAG, "location is null ...............");
}
}
示例4: onCreateDialog
import android.widget.Button; //導入方法依賴的package包/類
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View rootView = LayoutInflater.from(getContext()).inflate(R.layout.playlist_picker, new LinearLayout(getContext()), false);
rv = (RecyclerView) rootView.findViewById(R.id.rv);
MaterialDialog.Builder pickDialog = new MaterialDialog.Builder(getContext());
pickDialog.title(R.string.choose_playlist);
playlistListAdapter = new PlaylistListAdapter(getContext());
playlistListAdapter.setOnItemClickListener(onClick);
CustomLayoutManager customLayoutManager = new CustomLayoutManager(getContext());
customLayoutManager.setSmoothScrollbarEnabled(true);
rv.addItemDecoration(new DividerItemDecoration(getContext(), 75, false));
rv.setLayoutManager(customLayoutManager);
rv.setAdapter(playlistListAdapter);
ateKey = Helper.getATEKey(getContext());
colorAccent = Config.accentColor(getContext(), ateKey);
CreatePlaylist = (Button) rootView.findViewById(R.id.create_playlist);
CreatePlaylist.setOnClickListener(mOnClickListener);
CreatePlaylist.setBackgroundColor(colorAccent);
pickDialog.customView(rootView, false);
loadPlaylist();
return pickDialog.show();
}
示例5: showBtn
import android.widget.Button; //導入方法依賴的package包/類
void showBtn(){
String strs[]=new String[]{"Calc","Jump"};
int x=200,y=100,w=100,h=100;
for(int i=0;i<strs.length;i++) {
Button button = new Button(cxt);
button.setText(strs[i]);
button.setTag(strs[i]);
button.setBackgroundColor(Color.RED);
WindowManager.LayoutParams p = createLayoutParams(x*i+50, y, w, h);
initEvents(button);
map.put(button, p);
windowManager.addView(button, p);
}
}
示例6: initView
import android.widget.Button; //導入方法依賴的package包/類
private void initView() {
rlTitleBar = (RelativeLayout) findViewById(R.id.rlTitleBar);
tvTitle = (TextView) findViewById(R.id.tvTitle);
btnConfirm = (Button) findViewById(R.id.btnConfirm);
btnConfirm.setOnClickListener(this);
ivBack = (ImageView) findViewById(R.id.ivBack);
ivBack.setOnClickListener(this);
if (config != null) {
if (config.backResId != -1) {
ivBack.setImageResource(config.backResId);
}
if (config.statusBarColor != -1) {
StatusBarCompat.compat(this, config.statusBarColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
//透明狀態欄
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
rlTitleBar.setBackgroundColor(config.titleBgColor);
tvTitle.setTextColor(config.titleColor);
tvTitle.setText(config.title);
btnConfirm.setBackgroundColor(config.btnBgColor);
btnConfirm.setTextColor(config.btnTextColor);
}
}
示例7: genUrls
import android.widget.Button; //導入方法依賴的package包/類
private void genUrls(){
urlList = new ArrayList<>();
diffRes = new HashMap<>();
layoutSources.removeAllViews();
buttons = new ArrayList<>();
if(live.getUrllist() != null){
urlIndex = 0;
urlList = new ArrayList<>(Arrays.asList(live.getUrllist().split("#")));
for(String i:urlList){
String name = getName(i);
diffRes.put(name,i);
Button btn = new Button(getApplicationContext());
btn.setText(name);
btn.setWidth(MATCH_PARENT);
btn.setHeight(dp2px(48));
btn.setTextSize(18);
btn.setTextColor(Color.parseColor("#FFFFFF"));
btn.setBackgroundColor(Color.parseColor("#00ffffff"));
buttons.add(btn);
layoutSources.addView(btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
urlIndex = buttons.indexOf(v);
playTv(diffRes.get(((Button)v).getText()));
videoController.setIsLiveOrNot(true);
hideSettingLayout();
}
});
}
}else{
urlIndex = -1;
}
}
示例8: updateResPos
import android.widget.Button; //導入方法依賴的package包/類
private void updateResPos(){
for (Button i:buttons){
i.setBackgroundColor(Color.parseColor("#00ffffff"));
}
if(urlIndex < buttons.size()){
buttons.get(urlIndex).setBackgroundColor(Color.parseColor("#80000000"));
}
}
示例9: pickMe
import android.widget.Button; //導入方法依賴的package包/類
public void pickMe(View view) {
/*Bundle extras = getIntent().getExtras();
String userId = extras.getString("email");
assert userId != null;
String[] temp = userId.split("@");
userId = temp[0];*/
if (null != mCurrentLocation) {
String lat = String.valueOf(mCurrentLocation.getLatitude());
String lng = String.valueOf(mCurrentLocation.getLongitude());
if (checkBusSelection != 0) {
BUS = "b" + checkBusSelection;
DatabaseReference userDatabase = mDatabase.child(VEHICLE).child(BUS);
Map<String, String> userData = new HashMap<>();
userData.put(LATITUDE, lat);
userData.put(LONGITUDE, lng);
key = userDatabase.push().getKey();
Map<String, Map<String, String>> mSendingData = new HashMap<>();
mSendingData.put("LOCATION", userData);
/*Map<String, Map<String, Map<String, String>>> mFinalData = new HashMap<>();
mFinalData.put(INTERMEDIATE, mSendingData);*/
userDatabase.child(key).setValue(mSendingData);
Toast.makeText(MapsActivity.this, "REQUEST SENT", Toast.LENGTH_LONG).show();
Button button = (Button) findViewById(R.id.pick_me);
button.setClickable(false);
button.setBackgroundColor(Color.GREEN);
}
} else {
Log.d(TAG, "location is null ...............");
}
}
示例10: onCreate
import android.widget.Button; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView just creates the XML layouts
// defined in R.layout.activity_main.
// In this example, we'll make the layouts by using the Java code without XML
// so I just commented out setContentView.
//setContentView(R.layout.activity_main);
// 1. Generate Layout Parameter
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
);
// 2. Generate LinearLayout on this context.
LinearLayout baseLayout = new LinearLayout(this);
baseLayout.setOrientation(LinearLayout.VERTICAL);
baseLayout.setBackgroundColor(Color.rgb(0, 255, 0));
// 3. Draw the generated view by using setContentView.
setContentView(baseLayout, params);
// 4. Likely, make a Button View on the top.
Button button = new Button(this);
button.setText("Button");
button.setBackgroundColor(Color.MAGENTA);
// To add a view to the layout, use "addView" from the layout.
baseLayout.addView(button);
// From now on, we generated Views with Java, not XML.
// However, the state from now is the same.
// Therefore, we can use the views as we used before, like setting Listeners.
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "You clicked a button!", Toast.LENGTH_SHORT).show();
}
});
}
示例11: onCreate
import android.widget.Button; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings_dots_style);
//Show back button
ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setDisplayHomeAsUpEnabled(true);
ab.setHomeAsUpIndicator(R.mipmap.ic_arrow_back_white_24dp);
}
//Speak the title of the activity
Common.defaultTextSpeech.speechText(getString(R.string.dot_style));
//Buttons declaration
dotFillColor = (Button) findViewById(R.id.dotFillColor);
previousDotFillColor = Common.dotFillColor;
dotFillColor.setBackgroundColor(previousDotFillColor);
dotStrokeColor = (Button) findViewById(R.id.dotStrokeColor);
previousDotStrokeColor = Common.dotStrokeColor;
dotStrokeColor.setBackgroundColor(previousDotStrokeColor);
resetSettingsBtn = (Button) findViewById(R.id.resetSettingsBtn);
//Spinner declaration
dotRadiusPortraitSpinner = (Spinner) findViewById(R.id.dotRadiusPortraitSpinner);
dotRadiusLandscapeSpinner = (Spinner) findViewById(R.id.dotRadiusLandscapeSpinner);
//Portrait dots radius array list
int thePortraitDefaultDotRadius = Common.getDefaultDotRadius(0);
ArrayList<String> portraitDotRadiusList = new ArrayList<>();
for (int x = Common.MIN_DOT_RADIUS; x <= (thePortraitDefaultDotRadius + 20); x++) {
portraitDotRadiusList.add(String.format(Locale.getDefault(), "%d", x));
}
//Portrait dots radius adapter
portraitDotRadiusAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, portraitDotRadiusList);
portraitDotRadiusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dotRadiusPortraitSpinner.setAdapter(portraitDotRadiusAdapter);
dotRadiusPortraitSpinner.setSelection(portraitDotRadiusAdapter.getPosition(String.format(Locale.getDefault(), "%d", Common.getSettingInt("dotRadius", thePortraitDefaultDotRadius))), true);
//Landscape dots radius array list
int theLandscapeDefaultDotRadius = Common.getDefaultDotRadius(1);
ArrayList<String> landscapeDotRadiusList = new ArrayList<>();
for (int x = Common.MIN_DOT_RADIUS; x <= (theLandscapeDefaultDotRadius + 20); x++) {
landscapeDotRadiusList.add(String.format(Locale.getDefault(), "%d", x));
}
//Landscape dots radius adapter
landscapeDotRadiusAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, landscapeDotRadiusList);
landscapeDotRadiusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dotRadiusLandscapeSpinner.setAdapter(landscapeDotRadiusAdapter);
dotRadiusLandscapeSpinner.setSelection(landscapeDotRadiusAdapter.getPosition(String.format(Locale.getDefault(), "%d", Common.getSettingInt("dotLandscapeRadius", theLandscapeDefaultDotRadius))), true);
//Switches declaration
fillDotOnTouch = (CheckBox) findViewById(R.id.fillDotOnTouch);
fillDotOnTouch.setChecked(Common.fillDotOnTouch);
fillDotOnTouch.setOnCheckedChangeListener(this);
viewBrailleDotNumber = (CheckBox) findViewById(R.id.viewBrailleDotNumber);
viewBrailleDotNumber.setChecked(Common.viewBrailleDotNumber);
//Add listeners to spinners
initListeners(this);
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: themeButton
import android.widget.Button; //導入方法依賴的package包/類
public void themeButton(Button btn){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
btn.setTextColor(getTextColor());
btn.setBackgroundColor(getButtonBackgroundColor());
}
}
示例13: initItemViews
import android.widget.Button; //導入方法依賴的package包/類
public void initItemViews() {
if (items == null) {
Log.e(TAG, "Please call setItems before calling build");
return;
}
if (title != null) {
TextView titleView = new TextView(getContext());
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
param.bottomMargin = dp2px(1);
param.gravity = Gravity.CENTER;
titleView.setPadding(dp2px(0), dp2px(10), dp2px(0), dp2px(10));
titleView.setGravity(Gravity.CENTER);
titleView.setBackgroundColor(getColor(android.R.color.white));
titleView.setLayoutParams(param);
titleView.setText(title);
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
mPanel.addView(titleView);
}
for (int i = 0; i < items.size(); i ++) {
final String item = items.get(i);
final int index = i;
Button btn = new Button(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER;
params.bottomMargin = dp2px(1);
btn.setPadding(dp2px(0), dp2px(15), dp2px(0), dp2px(15));
btn.setText(item);
btn.setLayoutParams(params);
btn.setBackgroundColor(getColor(android.R.color.white));
if (i == initialSelection) {
btn.setTextColor(getColor(android.R.color.black));
} else {
btn.setTextColor(getColor(android.R.color.darker_gray));
}
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onItemSelectListener != null) {
onItemSelectListener.onItemSelected(index, item);
}
dismiss();
}
});
mPanel.addView(btn);
}
}
示例14: onCreate
import android.widget.Button; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button)findViewById(R.id.button);
TextView bootMode = (TextView) findViewById(R.id.textBootMode);
bootMode.setText(bootmode);
TextView codeName = (TextView) findViewById(R.id.textCodeName);
codeName.setText(Build.DEVICE);
TextView bootloader = (TextView) findViewById(R.id.textBootloader);
bootloader.setText(Build.BOOTLOADER);
TextView patchLevel = (TextView) findViewById(R.id.textPatchLevel);
patchLevel.setText(patch);
boolean isVuln = isVulnerable();
TextView vuln = (TextView) findViewById(R.id.textVulnerable);
if (shamu || angler) {
vuln.setTextColor(isVuln ? COLOR_RED : COLOR_GREEN);
b.setBackgroundColor(isVuln ? COLOR_RED : COLOR_GREEN);
vuln.setText(isVuln ? LABEL_VULN : LABEL_PATCHED);
}
TextView bm = (TextView) findViewById(R.id.textBootmodeAttack);
if (!"".equals(bootmode) && !normalBootmode.equals(bootmode))
{
bm.setText(LABEL_ATTACK);
}
vuln.setTextColor(isVulnerable() ? COLOR_RED : COLOR_GREEN);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(BLOG));
startActivity(i);
}
}
);
}
示例15: themeButton
import android.widget.Button; //導入方法依賴的package包/類
public void themeButton(Button btn) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
btn.setTextColor(getTextColor());
btn.setBackgroundColor(getButtonBackgroundColor());
}
}