Could someone help me out in changing a dialog box ListView font color and item background color (not the whole…
Could someone help me out in changing a dialog box ListView font color and item background color (not the whole dialog box background color)?
I have been messing around with the dialog boxes, trying to change most of their properties via code, not xml, or layout external files.
So far I have been able to change the title (font size, color, margins), the whole dialog box background, the buttons (font size, color and background color). But no luck so far with the items in a ListView. On my searches, it mostly came down to modifying the ArrayAdapter getView method, but I don’t know how to apply it in LL.
Below is the code for one of my dialog box ListView.
—————————————————————————-
bindClass(“android.app.Dialog”);
bindClass(“android.app.AlertDialog”);
bindClass(“android.content.DialogInterface”);
bindClass(“android.graphics.drawable.ColorDrawable”);
bindClass(“android.view.Gravity”);
//LL.bindClass(“android.R.color”);
//LL.bindClass(“android.graphics.Color”);
//LL.bindClass(“android.app.Activity”);
//LL.bindClass(“android.view.Window”);
//LL.bindClass(“android.view.WindowManager”);
//LL.bindClass(“android.view.ViewGroup.LayoutParams”);
LL.bindClass(“android.widget.LinearLayout”);
LL.bindClass(“android.widget.TextView”);
LL.bindClass(“android.widget.EditText”);
LL.bindClass(“android.text.InputType”);
//LL.bindClass(“android.widget.Adapter”);
LL.bindClass(“android.widget.ArrayAdapter”);
LL.bindClass(“android.widget.ListView”);
LL.bindClass(“android.widget.AdapterView”);
var context = LL.getContext();
var colorBg = 0xAA99AAFF;
var itemsMenu = [“Message”,”List”,”Checkbox List”,”Text Input”,”Custom List”];
var itemsMenuDialog = [dialogMessageShow,dialogListShow,dialogCheckboxShow,dialogTextInputShow,dialogCListShow];
//var myItemsState = [];
var myItems = [“Easy”,”Medium”,”Hard”,”Very Hard”];
//for(var i=0; i //myItemsState[2] = true; dialogMenuShow(); //Android.makeNewToast(“done”, true).show(); //var dialog = new AlertDialog.Builder(context).setMessage(“Hello world”).show(); function dialogButtonHandler(button){ var msg = “”; switch (button) { case Dialog.BUTTON_POSITIVE: msg = “positive”; break; case Dialog.BUTTON_NEGATIVE: msg = “negative”; break; case Dialog.BUTTON_NEUTRAL: msg = “neutral”; break; } msg = button + ” | ” + msg + ” ” + “\n” + “Running again”; Android.makeNewToast(msg,true).show(); } function myText(text){ if (typeof text == undefined){var text=””;} var myTV = new TextView(context); myTV.setText(text); myTV.setTextColor(0xDD00FF99); myTV.setTextSize(22); //title.setBackgroundResource(R.drawable.gradient); myTV.setPadding(10, 10, 10, 10); myTV.setGravity(Gravity.CENTER); return myTV; } function dialogMenuShow(){ var dialogExit = false; var builder = new AlertDialog.Builder(context); //builder.setTitle(“Select the Dialog to show”); builder.setCustomTitle(myText(“Select the Dialog to show:”)); builder.setItems(itemsMenu,new DialogInterface.OnClickListener(){ onClick:function(dialog, indexSelected) {dialog.cancel(); //Android.makeNewToast(itemsMenu[indexSelected],true).show(); //itemsMenuDialog[indexSelected](); //itemsMenuDialog[indexSelected](myItems,myItemsState); switch (indexSelected) { case 0: itemsMenuDialog[indexSelected](myItems.join(“, “)); break; //Message case 1: itemsMenuDialog[indexSelected](myItems); break; //List case 2: //itemsMenuDialog[indexSelected](myItems,myItemsState); itemsMenuDialog[indexSelected](myItems); break; //Checkbox case 3: itemsMenuDialog[indexSelected](“Input some text:”,”sample text”); break; //Text Input case 4: itemsMenuDialog[indexSelected](myItems); break; //Custom List } } }); builder.setPositiveButton(“OK”, new DialogInterface.OnClickListener() { onClick:function(dialog, buttonId) {dialogButtonHandler(buttonId);} }); builder.setNeutralButton(“Test”, new DialogInterface.OnClickListener() { onClick:function(dialog, buttonId) {dialogButtonHandler(buttonId);} }); builder.setNegativeButton(“Close”, new DialogInterface.OnClickListener() { onClick:function(dialog, buttonId) {dialog.cancel();dialogButtonHandler(buttonId);} }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { onCancel:function(dialog) {dialogExit = true;} }); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { onDismiss:function(dialog) { if (dialogExit) {//dialogMenuShow();{} } else {dialogMenuShow();} //setTimeout(dialogListShow(),0);//shows the list again. On a timeout so the startActivity() is correctly launched before //cancell is called when explicit set, pressing the back key / default action is dismiss / after cancel, dissmiss gets called too } }); var dialog = builder.create(); //dialog.setCancelable(true); //dialog.setCancelable(false); //dialog.setCanceledOnTouchOutside(false); //default = true var window = dialog.getWindow(); window.setBackgroundDrawable(new ColorDrawable(colorBg)); //window.setGravity(Gravity.FILL_VERTICAL); //window.setGravity(Gravity.CENTER); //window.setTextColor(Color.LTGRAY); //window.setTextSize(24); dialog.show(); dialog.getButton(Dialog.BUTTON_POSITIVE).setTextSize(24); dialog.getButton(Dialog.BUTTON_POSITIVE).setTextColor(0xBBDDDDDD); dialog.getButton(Dialog.BUTTON_POSITIVE).setBackgroundColor(0xFF556644); dialog.getButton(Dialog.BUTTON_NEGATIVE).setTextSize(12); //dialog.getButton(Dialog.BUTTON_NEGATIVE).setCustomText(title); //dialog.getButton(Dialog.BUTTON_NEGATIVE).setText(title); //dialog.getButton(Dialog.BUTTON_NEGATIVE).setView(title); //not available dialog.getButton(Dialog.BUTTON_NEUTRAL).setTextSize(24); dialog.getButton(Dialog.BUTTON_NEUTRAL).setTextColor(0xFF0000AA); }
bindClass(“android.app.AlertDialog“);
bindClass(“android.widget.ArrayAdapter“);
bindClass(“android.R”);
bindClass(“android.widget.TextView“);
var items = [“item A”,”item B”];
var context = getActiveScreen().getContext();
var adapter = new JavaAdapter(ArrayAdapter, {
getView:function(position,convertView,parent){
var view = this.super$getView(position,convertView,parent);
view.setBackgroundColor(0xffff0000);
return view;
}
},context,R.layout.simple_list_item_1,items);
new AlertDialog.Builder(context).setAdapter(adapter,function(dialog,which){
Toast.makeText(context,items[which],Toast.LENGTH_SHORT).show();}).show();
Using JavaAdapter, you can create subclasses at runtime. That allows you to override getView, as seen above.
thank you!
one more question,
the “R.layout.simple_list_item_1″ is a default android layout, or LLx layout?
Like, if someone not running LLx would be able to make minor changes to the code (mostly change the class binding) and it will run?
As you can see I’m binding android.R, so it is defined by android.
Lightning specific is:
– bindClass
– getActiveScreen
– using Toast without binding it first.
Someone not running llx usually doesn’t have a javascript environment though, so I don’t see how it would be useful to them.
just a thought, maybe someone using tasker can be able use it
thanks again,
you solved about a week of research and about 3 days of frustration within a few hours