Main Activity Screen我制作了一个带有textview的自定义日历,所以我希望日历在打开日历时显示当前日期和月份...
`我的日历应在当月直接打开并显示当前日期,就像Google日历一样。
<TextView
android:textColor="@color/Blue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/caviardreams"
android:gravity="top|center"
android:text="1"
android:textSize="11sp"
android:textStyle="bold"
android:maxWidth="1dp"
android:maxHeight="1dp"/>
<TextView
android:textColor="@color/Blue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/caviardreams"
android:gravity="top|center"
android:text="2"
android:textSize="11sp"
android:textStyle="bold"
android:maxWidth="1dp"
android:maxHeight="1dp"/>
<TextView
android:textColor="@color/Blue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/caviardreams"
android:gravity="top|center"
android:text="3"
android:textSize="11sp"
android:textStyle="bold"
android:maxWidth="1dp"
android:maxHeight="1dp"/>
`
我希望当前日期在当前月份突出显示。
这是MainActivity的Java代码
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
ViewPager viewPager;
EditText txt;
Button btn;
String str;
AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
//admob app id
MobileAds.initialize(this,"ca-app-pub-6376378742627184~5911477780");
adView = (AdView)findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
adView.loadAd(adRequest);
}
public void date(View view) {
}
private class MyPagerAdapter extends FragmentStatePagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int pos) {
switch(pos) {
case 0: return Frag1.newInstance("Frag1, Instance 1");
case 1: return Frag2.newInstance("Frag2, Instance 2");
case 2: return Frag3.newInstance("Frag3, Instance 3");
case 3: return Frag4.newInstance("Frag4, Instance 4");
case 4: return Frag5.newInstance("Frag5, Instance 5");
case 5: return Frag6.newInstance("Frag6, Instance 6");
case 6: return Frag7.newInstance("Frag7, Instance 7");
case 7: return Frag8.newInstance("Frag8, Instance 8");
case 8: return Frag9.newInstance("Frag9, Instance 9");
case 9: return Frag10.newInstance("Frag10, Instance 10");
case 10: return Frag11.newInstance("Frag11, Instance 11");
case 11: return Frag12.newInstance("Frag12, Instance 12");
default: return Frag1.newInstance("Frag1, Default");
}
}
@Override
public int getCount() {
return 12;
}
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
finish();
System.exit(0);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, 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) {
finish();
System.exit(0);
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
ApplicationInfo app = getApplicationContext().getApplicationInfo();
String filePath = app.sourceDir;
int id = item.getItemId();
if (id == R.id.home)
{
// Handle the camera action
Intent a = new Intent(MainActivity.this,MainActivity.class);
startActivity(a);
}
else if (id == R.id.about)
{
Intent b = new Intent(MainActivity.this,About.class);
startActivity(b);
}
else if (id == R.id.nav_share)
{
Intent c = new Intent(Intent.ACTION_SEND);
c.setType("*/*");
String shareBody = "https://play.google.com/store/apps/details?id=com.jangphong.hem.karbicalender2";
String shareSub = "Download Karbi calendar 2019";
c.putExtra(Intent.EXTRA_SUBJECT,shareSub);
c.putExtra(Intent.EXTRA_TEXT,shareBody);
c.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(filePath)));
startActivity(Intent.createChooser(c,"Share using"));
}
else if (id == R.id.feedback)
{
Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.karbidigitalresources.tk"));
startActivity(in);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
这是清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jangphong.hem.karbicalender2">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_karbi_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_karbi_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".About" />
<activity
android:name=".SplashScreen"
android:noHistory="true"
android:theme="@style/AppTheme.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".edit_text" />
<activity android:name=".feb" />
<activity android:name=".march" />
<activity android:name=".april" />
<activity android:name=".may" />
<activity android:name=".june" />
<activity android:name=".july" />
<activity android:name=".august" />
<activity android:name=".sep" />
<activity android:name=".oct" />
<activity android:name=".nov" />
<activity android:name=".dec"></activity>
</application>