我可以使用一个简单的代码块自定义infoWindow的内容:
private GoogleMap mMap;
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker arg0) {
View v = getLayoutInflater().inflate(R.layout.custom_infowindow, null);
return v;
}
});
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#55000000" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HELLO"
android:textColor="#FF0000"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
但这只会改变内容,而不会改变infoWindow本身.它仍然保持白色,底部有一个小阴影,现在红色的HELLO文字可见黑色bg.我想将此默认infoWindow更改为透明的黑色矩形.我怎样才能做到这一点?
我有一个edittext,我想计算其中的单词.编辑文本中有新行时出错.
我试过这个:
String[] WC = et_note.getText().toString().split(" ");
Log.i("wordcount", "wc: " + WC.length);
Run Code Online (Sandbox Code Playgroud)
这是一个文本 - > wc:4
这是
一个
文字 - > wc:4
这是
一个简单的
文字 - > wc:4
有任何想法吗?
我正在构建一个简单的聊天应用程序,用户可以在其中发送文本和表情符号.我可以将文字和表情符号发送到另一部手机.我的问题是:
1.当我输入内容并添加表情符号时:
然后我无法在图像之前和之后输入任何文本.我可以在"o"字母前面写.系统"看到"我输入的内容,所以即使我在笑脸后输入"Honey",我也看不到它,但EditText会注册它并发送消息:
2.当我向Edittext添加一个表情符号然后删除它时,我无法输入任何内容,因为删除的表情符号出现了.它只出现一次,所以无论我输入多少个字符,EditText看起来就像我删除表情符号之前,但文本是在没有表情符号的情况下发送的,就像在所有三种情况下一样.
3.当我在EditText中输入"something"时,在"some"之后插入一个表情符号:
然后我将光标放在表情符号后面并删除它,这里剩下的是:
但是当我按下发送按钮时会发送正确的消息:
这就是表情符号按钮监听器内部的内容(当我单击表情符号将其添加到EditText时,此方法被激活).
ib_happy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int cursorPosition = mOutEditText.getSelectionStart();
mOutEditText.getText().insert(cursorPosition, smileys[0]);
SpannableStringBuilder ssb = new SpannableStringBuilder(mOutEditText.getText());
ssb.setSpan(new ImageSpan(bitmapArray.get(0), ImageSpan.ALIGN_BASELINE), cursorPosition, cursorPosition+2, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
mOutEditText.setText(ssb, BufferType.SPANNABLE);
mOutEditText.setSelection(cursorPosition+2);
dialog_emoticon.dismiss();
}
});
Run Code Online (Sandbox Code Playgroud) 图表上的字体大小很小,难以阅读某些颜色.有没有办法改变这些属性?
我可以这样做,使整个馅饼红色,但设置颜色或字体大小不会改变:
.ct-series-x .ct-slice-pie {
fill: #f05b4f
}
<div class="ct-chart ct-golden-section ct-series-x ct-slice-pie" id="chart2"></div>
Run Code Online (Sandbox Code Playgroud) 我如何按日期或名称对此数组进行排序?
String[][] datetable= new String[21][2];
datetable[0][0] = "2011.01.01";
datetable[0][1] = "Name1";
datetable[1][0] = "2011.01.03";
datetable[1][1] = "Name2";
.
.
.
datetable[20][0] = "2011.02.16";
datetable[20][1] = "Name3";
Run Code Online (Sandbox Code Playgroud) 我有一个由名称和分数组成的字符串数组.我想按分数对该数组进行排序.问题是,考虑到它是一个字符串数组,分数是字符串,导致13,16,2,5,6而不是2,5,6,13,16.我正在使用此代码:
int spaceIndex;
String[][] scoreboard;
String[] playername;
String[] score;
int sbsize;
array1.add("Thomas" + ":" + 5);
array1.add("Blueb" + ":" + 6);
array1.add("James" + ":" + 16);
array1.add("Hleb" + ":" + 13);
array1.add("Sabbat" + ":" + 2);
sbsize = array1.size();
scoreboard = new String[sbsize][2];
playername = new String[sbsize];
score = new String[sbsize];
pos2 = new int[sbsize];
for (int i=0; i<array1.size(); i++)
{
spaceIndex = array1.get(i).indexOf(':');
scoreboard[i][0] = array1.get(i).substring(0, spaceIndex);
scoreboard[i][1] = array1.get(i).substring(spaceIndex+1, array1.get(i).length());
}
Arrays.sort(scoreboard, new Comparator<String[]>() {
@Override
public int …
Run Code Online (Sandbox Code Playgroud) 基于本教程, 我创建了一个应该显示时间的小部件.java方式有效,但服务方式没有.
HelloWidget.java:
public class HelloWidget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Intent intent = new Intent(context, UpdateService.class);
context.startService(intent);
}
}
Run Code Online (Sandbox Code Playgroud)
UpdateService.java:
public final class UpdateService extends Service {
@Override
public void onStart(Intent intent, int startId) {
RemoteViews updateViews = new RemoteViews(this.getPackageName(), R.layout.main);
Date date = new Date();
java.text.DateFormat format = SimpleDateFormat.getTimeInstance(
SimpleDateFormat.MEDIUM, Locale.getDefault());
updateViews.setTextViewText(R.id.widget_textview, "Current Time " + format.format(date));
ComponentName thisWidget = new ComponentName(this, HelloWidget.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(thisWidget, updateViews); …
Run Code Online (Sandbox Code Playgroud) 经过数周的编程后,我决定完成我的申请.上次我无法写文件和阅读,现在我想做.我也许可以使用数据库,但这似乎更容易.我从我复制粘贴代码的地方找到了这个页面.至少现在我能够检查手机上文件的内容(我暂时没有使用任何虚拟SD卡,但它肯定会加速测试).问题在于这个代码,每次我写文件,关闭我的应用程序,然后重新打开它并再次写入文件,文件的内容被重置.
File root = Environment.getExternalStorageDirectory();
File file = new File(root, "tomato50.txt");
if (assignArr.size() > 0) {
try {
if (root.canWrite()) {
FileWriter filewriter = new FileWriter(file);
BufferedWriter out = new BufferedWriter(filewriter);
for (int i = 0; i < assignArr.size(); i++) {
out.write(assignArr.get(i) + "\n");
Toast.makeText(MainActivity.this,
"out: " + assignArr.get(i), Toast.LENGTH_LONG)
.show();
}
out.close();
}
} catch (IOException e) {
Log.e("TAG", "Could not write file " + e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
例如
我有一个ExpandableListView,我想在点击一组时记录groupposition.不幸的是,下面的代码总是返回0,好像我点击了第0组.
exList.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
groupPosition = ExpandableListView.getPackedPositionGroup(id);
Log.i("group position", groupPosition + "");
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
我也有一个longclicklistener对群体和孩子工作正常:
exList.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
groupPosition = ExpandableListView.getPackedPositionGroup(id);
...
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我想在电子邮件中同时发送html和纯文本.我发现这个非常简单的教程,但它使用mail()函数发送电子邮件.如何转换此代码发送带有PHP Mailer类的电子邮件?
//specify the email address you are sending to, and the email subject
$email = 'email@example.com';
$subject = 'Email Subject';
//create a boundary for the email. This
$boundary = uniqid('np');
//headers - specify your from email address and name here
//and specify the boundary for the email
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: Your Name \r\n";
$headers .= "To: ".$email."\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
//here is the content body
$message = "This …
Run Code Online (Sandbox Code Playgroud)