1.
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); // thread for displaying the SplashScreen Thread splashTread = new Thread() { @Override public void run() { try { int waited = 0; while(_active && (waited < _splashTime)) { sleep(100); if(_active) { waited += 100; } } } catch(InterruptedException e) { // do nothing } finally { finish(); startActivity(new Intent("com.droidnova.android.splashscreen.MyApp")); stop(); } } }; splashTread.start(); }
就是闪屏的activity中 加入一个线程 然后其他主activity就可以了
2.
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); new Handler().postDelayed(new Runnable(){ @Override public void run() { finish(); startActivity(new Intent("com.droidnova.android.splashscreen.MyApp")); } }, _splashTime); }
<?
xml version
=
"1.0"
encoding
=
"utf-8"
?>
<LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
android:orientation
=
"vertical"
android:fadingEdgeLength
=
"0sp"
>
<LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:id
=
"@+id/myTitleBarLayout"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:orientation
=
"vertical"
>
<TextView
android:id
=
"@+id/myTitleBarTextView"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:text
=
"@string/app_name"
android:paddingTop
=
"4dip"
android:paddingBottom
=
"4dip"
android:paddingLeft
=
"6dip"
android:textStyle
=
"bold"
android:shadowColor
=
"#BB000000"
android:shadowRadius
=
"3.0"
android:shadowDy
=
".25"
/>
<View
android:layout_width
=
"fill_parent"
android:layout_height
=
"1dip"
android:background
=
"#CCEEEEEE"
android:padding
=
"10dip"
/>
</LinearLayout>
<ScrollView
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
android:layout_weight
=
"1"
>
<!-- Insert
your regular layout stuff here -->
<Button
android:id
=
"@+id/toggle_title_button"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
"Toggle Title"
/>
</ScrollView>
</LinearLayout>
然后
package
com
.
test
.
HelloGridView
;
import
android
.
app
.
Activity
;
import
android
.
os
.
Bundle
;
import
android
.
view
.
View
;
import
android
.
view
.
Window
;
import
android
.
view
.
View
.
OnClickListener
;
import
android
.
widget
.
Button
;
import
android
.
widget
.
LinearLayout
;
import
android
.
widget
.
TextView
;
public
class
HelloGridView
extends
Activity
{
public
void
onCreate
(
Bundle
savedInstanceState
)
{
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
main
);
TextView
tv
=
(
TextView
)
this
.
findViewById
(
R
.
id
.
myTitleBarTextView
);
tv
.
setBackgroundColor
(
0xFF848284
);
tv
.
setTextColor
(
0xFFFFFFFF
);
Button
toggleTitleButton
=
(
Button
)
this
.
findViewById
(
R
.
id
.
toggle_title_button
);
toggleTitleButton
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
LinearLayout
ll
=
(
LinearLayout
)
findViewById
(
R
.
id
.
myTitleBarLayout
);
if
(
ll
.
getVisibility
()
==
View
.
GONE
)
{
ll
.
setVisibility
(
View
.
VISIBLE
);
}
else
{
ll
.
setVisibility
(
View
.
GONE
);
}
}
});
}
}
有时候也可以
通过
private
void
updateFullscreenStatus
(
bUseFullscreen
)
{
if
(
bUseFullscreen
)
{
getWindow
().
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_FULLSCREEN
);
getWindow
().
clearFlags
(
WindowManager
.
LayoutParams
.
FLAG_FORCE_NOT_FULLSCREEN
);
}
else
{
getWindow
().
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_FORCE_NOT_FULLSCREEN
);
getWindow
().
clearFlags
(
WindowManager
.
LayoutParams
.
FLAG_FULLSCREEN
);
}
m_contentView
.
requestLayout
();
}
通
过两种方法 就可以去掉状态栏和标题栏了这个用在游戏中比较好.,上述方法是通过标题栏实现的
3.通过主题实现隐藏状态栏和标 题栏
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
public class MapManager {
//==============================Singleton===========================================
private volatile static MapManager manager;
private LocationManager lm;
private MapController mapController;
private GeoPoint currentPoint;
private MapManager(Context c){
lm = (LocationManager)c.getSystemService(Context.LOCATION_SERVICE);
}
public static MapManager getInstance(Context c){
if(manager == null){
synchronized (MapManager.class) {
if(manager == null){
manager = new MapManager(c);
}
}
}//if
return manager;
}
//=====================================监听器=============================================================
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location loc) { //当坐标改变时触发此函数,如果Provider传进相同的坐标,它就不会被触发
// log it when the location changes
if (loc != null) {
GeoPoint myPoint = new GeoPoint((int)loc.getLatitude()*1000000, (int)loc.getLongitude()*1000000);
mapController.setCenter(myPoint);
}
}
public void onProviderDisabled(String provider) {
// Provider被disable时触发此函数,比如GPS被关闭
}
public void onProviderEnabled(String provider) {
// Provider被enable时触发此函数,比如GPS被打开
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// Provider的转态在可用、暂时不可用和无服务三个状态直接切换时触发此函数
}
};
//*********************************对外的接口*******************************************************
public void startAutoUpdate(){
lm.requestLocationUpdates("gps", 0, 1000, locationListener);
}
public void setCurrentLocToCenter(MapController mapController){
this.mapController = mapController;
//得到当前位置信息,设置在地图上
Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
currentPoint = new GeoPoint((int)loc.getLatitude()*1000000, (int)loc.getLongitude()*1000000);
mapController.setCenter(currentPoint);
}
public void addCurrentOverLapToMap(MapView mapView){
//绘制提示信息
MyOverlay mo = new MyOverlay(currentPoint);
mo.onTap(currentPoint, mapView);
mapView.getOverlays().add(mo);
}
//===================================悬浮层定义=============================================================
protected class MyOverlay extends Overlay{
private GeoPoint point;
public MyOverlay(GeoPoint point){
this.point = point;
}
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
//转换地图的经纬度到像素 Geopoint ----> point
Point screenXY = new Point();
mapView.getProjection().toPixels(point, screenXY);
String warning = "I'm here";
//绘制一个方框
Paint p = new Paint();
p.setStyle(Style.FILL);
p.setAntiAlias(true);
//p.setColor(Color.BLUE);
p.setARGB(128, 255, 0, 0);
float warningWidth = p.measureText(warning);
float width = warningWidth + 0.5f;
float high = 25;
RectF roundRect = new RectF(screenXY.x-width/2-2, screenXY.y, screenXY.x+width/2+2, screenXY.y+high);
canvas.drawRoundRect(roundRect, 5, 5, p);
//p.setARGB(255, 51, 51, 255);
//绘制文字“ I'm here ”
p.setColor(Color.BLUE);
canvas.drawText(warning, screenXY.x-width/2-2, screenXY.y+high+1, p);
p.setColor(Color.GREEN);
canvas.drawCircle(screenXY.x, screenXY.y, 3, p);
}
}
}