我了解到您无法将事件添加到默认日历视图(它只是在用户的默认日历中处理)所以我使用的是caldroid https://github.com/roomorama/Caldroid/blob/master/README.md到目前为止,对文档很有帮助,但是当涉及到一件事时,我就迷失了。
我想要做的是更改任何有事件的日期的颜色。文档说要制作一个可绘制并将其放入单元格中,但我对如何做到这一点更加迷茫,所以我认为更改单元格的颜色会更容易。
我当前的代码看起来像这样
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.text.format.DateUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.roomorama.caldroid.CaldroidFragment;
import com.roomorama.caldroid.CaldroidListener;
import java.util.Calendar;
import java.util.Date;
public class CalendarActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calendar);
CaldroidFragment caldroidFragment = new CaldroidFragment();
Bundle args = new Bundle();
Calendar cal = Calendar.getInstance();
args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1);
args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR));
caldroidFragment.setArguments(args);
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
t.replace(R.id.calendarLayout, caldroidFragment);
t.commit();
final CaldroidListener listener = new CaldroidListener() {
@Override
public void onSelectDate(Date date, View view) {
Toast.makeText(getApplicationContext(), date.toString(),
Toast.LENGTH_SHORT).show();
}
@Override
public void onChangeMonth(int month, int year) {
String text = "month: " + month + " year: " + year;
Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT).show();
}
@Override
public void onLongClickDate(Date date, View view) {
Toast.makeText(getApplicationContext(),
"Long click " + date.toString(),
Toast.LENGTH_SHORT).show();
}
@Override
public void onCaldroidViewCreated() {
Toast.makeText(getApplicationContext(),
"Caldroid view is created",
Toast.LENGTH_SHORT).show();
}
};
caldroidFragment.setCaldroidListener(listener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_calendar, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
我在这里检查过更改网格单元格的颜色使用意图编辑日历事件在此处不起作用 Caldroid 不刷新,在这里我想更改日历上事件的字体颜色,但我不知道该怎么做。
我知道我可以使用 caldroidFragment.setBackgroundResourceForDate(R.color.blue, blueDate); 更改日期的颜色;但我不确定如何使其与有事件的日期相对应。如果有人可以帮助我,将不胜感激。还有,母亲节快乐!
我刚刚偶然发现了这段代码,并且正在实施它。
@Override public void onSelectDate(Date date, View view) { Toast.makeText(getApplicationContext(), formatter.format(date), Toast.LENGTH_SHORT).show();
}
@Override
public void onChangeMonth(int month, int year) {
String text = "month: " + month + " year: " + year;
Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT).show();
}
@Override
public void onLongClickDate(Date date, View view) {
Toast.makeText(getApplicationContext(),
"Long click " + formatter.format(date),
Toast.LENGTH_SHORT).show();Calendar cal = Calendar.getInstance();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", System.currentTimeMillis());
intent.putExtra("endTime", System.currentTimeMillis()+60000);
intent.putExtra("title", "hiii");
startActivity(intent);
caldroidFragment.refreshView();
}
@Override
public void onCaldroidViewCreated() {
if (caldroidFragment.getLeftArrowButton() != null) {
Toast.makeText(getApplicationContext(),
"Caldroid view is created", Toast.LENGTH_SHORT)
.show();
}
}
};final CaldroidListener listener = new CaldroidListener() {
@Override
public void onSelectDate(Date date, View view) {
Toast.makeText(getApplicationContext(), formatter.format(date),
Toast.LENGTH_SHORT).show();
}
@Override
public void onChangeMonth(int month, int year) {
String text = "month: " + month + " year: " + year;
Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT).show();
}
@Override
public void onLongClickDate(Date date, View view) {
Toast.makeText(getApplicationContext(),
"Long click " + formatter.format(date),
Toast.LENGTH_SHORT).show();Calendar cal = Calendar.getInstance();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", System.currentTimeMillis());
intent.putExtra("endTime", System.currentTimeMillis()+60000);
intent.putExtra("title", "hiii");
startActivity(intent);
caldroidFragment.refreshView();
}
@Override
public void onCaldroidViewCreated() {
if (caldroidFragment.getLeftArrowButton() != null) {
Toast.makeText(getApplicationContext(),
"Caldroid view is created", Toast.LENGTH_SHORT)
.show();
}
}
};