![这里写图片描述](https://img-blog.csdn.net/20151015211248116)
![这里写图片描述](https://img-blog.csdn.net/20151015212537562)
android.support.v7.app.ActionBar actionBar = getSupportActionBar()
actionBar.hide()
![这里写图片描述](https://img-blog.csdn.net/20151015212616320)
![这里写图片描述](https://img-blog.csdn.net/20151015213727479)
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
}
public void startActivity(View v){
startActivity(new Intent(this, Main2Activity.class));
}
}
public class Main2Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
ActionBar supportActionBar = getSupportActionBar();
supportActionBar.setDisplayHomeAsUpEnabled(true);
}
<activity
android:name=".Main2Activity"
android:label="@string/title_activity_main2"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
-----------------------------
<item
android:id="@+id/serch"
android:icon="@android:drawable/ic_menu_search"
android:orderInCategory="300"
android:title="search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" />
<item
android:id="@+id/share"
android:icon="@android:drawable/ic_menu_share"
android:orderInCategory="400"
app:showAsAction="ifRoom"
android:title="share"
----------------------
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem item = menu.findItem(R.id.serch);
SearchView searchView = (SearchView) item.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Toast.makeText(getApplicationContext(), query, Toast.LENGTH_LONG).show();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
=================================================
MenuItem shareItem = menu.findItem(R.id.share);
ShareActionProvider mShareActionProvider = (ShareActionProvider)
MenuItemCompat.getActionProvider(shareItem);
mShareActionProvider.setShareIntent(getDefaultIntent());
return true;
}
private Intent getDefaultIntent() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
return intent;
}
![这里写图片描述](https://img-blog.csdn.net/20151015214613019)
![这里写图片描述](https://img-blog.csdn.net/20151017152200797)
![这里写图片描述](https://img-blog.csdn.net/20151017185751366)
public class MainActivity extends AppCompatActivity implements ActionBar.TabListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.addTab(actionBar.newTab().setText("新闻").setTabListener(this));
actionBar.addTab(actionBar.newTab().setText("视屏").setTabListener(this));
actionBar.addTab(actionBar.newTab().setText("音乐").setTabListener(this));
actionBar.addTab(actionBar.newTab().setText("游戏").setTabListener(this));
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
Toast.makeText(this,tab.getText(),Toast.LENGTH_SHORT).show();
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
}
![这里写图片描述](https://img-blog.csdn.net/20151018181435333)
![这里写图片描述](https://img-blog.csdn.net/20151018181453622)
![这里写图片描述](https://img-blog.csdn.net/20151018181616194)
权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
//电话服务管理的API方法
public void testTelePhoneManager() {
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)
System.out.print("电话状态:" + tm.getCallState())
System.out.print("唯一的设备ID:" + tm.getDeviceId())
System.out.print("设备的软件版本号:" + tm.getDeviceSoftwareVersion())
System.out.print("手机号:" + tm.getLine1Number())
System.out.print("获取ISO标准的国家码,即国际长途区号:" + tm.getLine1Number())
System.out.print("当前使用的网络类型:" + tm.getNetworkType())
System.out.print("手机类型:" + tm.getPhoneType())
System.out.print("SIM的状态信息:" + tm.getSimState())
System.out.print("唯一的用户ID:" + tm.getSubscriberId())
System.out.print("SIM卡的序列号:" + tm.getSimSerialNumber())
System.out.print("服务商名称:" + tm.getSimOperator())
}
public class MainActivity extends AppCompatActivity {
TextView t01
TextView t02
TextView t03
TextView t04
TextView t05
TextView t06
TextView t07
TextView t08
TextView t09
TextView t10
TextView t11
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
t01 = (TextView) findViewById(R.id.t01)
t02 = (TextView) findViewById(R.id.t02)
t03 = (TextView) findViewById(R.id.t03)
t04 = (TextView) findViewById(R.id.t04)
t05 = (TextView) findViewById(R.id.t05)
t06 = (TextView) findViewById(R.id.t06)
t07 = (TextView) findViewById(R.id.t07)
t08 = (TextView) findViewById(R.id.t08)
t09 = (TextView) findViewById(R.id.t09)
t10 = (TextView) findViewById(R.id.t10)
t11 = (TextView) findViewById(R.id.t11)
testTelePhoneManager()
}
//电话服务管理的API方法
public void testTelePhoneManager() {
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)
t01.setText("电话状态:" + tm.getCallState())
t02.setText("唯一的设备ID:" + tm.getDeviceId())
t03.setText("设备的软件版本号:" + tm.getDeviceSoftwareVersion())
t04.setText("手机号:" + tm.getLine1Number())
t05.setText("获取ISO标准的国家码,即国际长途区号:" + tm.getLine1Number())
t06.setText("当前使用的网络类型:" + tm.getNetworkType())
t07.setText("手机类型:" + tm.getPhoneType())
t08.setText("SIM的状态信息:" + tm.getSimState())
t09.setText("唯一的用户ID:" + tm.getSubscriberId())
t10.setText("SIM卡的序列号:" + tm.getSimSerialNumber())
t11.setText("服务商名称:" + tm.getSimOperator())
//监听打电话的状态
tm.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_CALL_STATE)
}
//电话监听事件:
private class MyPhoneStateListener extends PhoneStateListener {
//电话监听状态:
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber)
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
Toast.makeText(MainActivity.this, "挂机状态", Toast.LENGTH_LONG).show()
break
case TelephonyManager.CALL_STATE_RINGING:
Toast.makeText(MainActivity.this, "电话响铃状态", Toast.LENGTH_LONG).show()
break
case TelephonyManager.CALL_STATE_OFFHOOK:
Toast.makeText(MainActivity.this, "接听状态", Toast.LENGTH_LONG).show()
break
}
}
}
}
![这里写图片描述](https://img-blog.csdn.net/20151018181630669)
![这里写图片描述](https://img-blog.csdn.net/20151018181734504)
![这里写图片描述](https://img-blog.csdn.net/20151018181752043)
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
testTelePhoneManager();
}
public void testTelePhoneManager() {
sendBroadcast(new Intent(this,PhoneListenerReceiver.class));
}
public class PhoneListenerReceiver extends BroadcastReceiver {
public PhoneListenerReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager tm = (TelephonyManager) context.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(new MyPhoneStateListener(context), PhoneStateListener.LISTEN_CALL_STATE);
}
static WindowManager wm = null;
private class MyPhoneStateListener extends PhoneStateListener {
private Context context;
TextView textView = null;
public MyPhoneStateListener(Context context) {
this.context = context;
}
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
if (state == TelephonyManager.CALL_STATE_RINGING) {
wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
textView = new TextView(context);
textView.setText("当前电话号码:" + incomingNumber);
wm.addView(textView, params);
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
if (wm != null) {
wm.removeView(textView);
wm = null;
}
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zhangjianbin.myapplication" >
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".PhoneListenerReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>