在string.xml中添加字符串資源
<string name="call">撥打電話至本人</string>
在布局文件中舔涎,添加撥打號碼的按鈕并把其放于相應(yīng)位置
在豎直布局fragment_crime.xml中添加代碼:
<Button
android:id="@+id/crime_callButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="@string/call" />
在水平布局fragment_crime.xml(land)當(dāng)中添加代碼:
<Button
android:id="@+id/crime_callButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/call" />
在CrimeFragment當(dāng)中對該按鈕設(shè)置監(jiān)聽等操作
private Button mCallButton;
mCallButton = (Button)v.findViewById(R.id.crime_callButton);
mCallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri number = Uri.parse("tel:5551234");
Intent i = new Intent(Intent.ACTION_DIAL, number);
startActivity(i);
}
});
如下為實(shí)現(xiàn)效果
QQ截圖20170425103607.png
QQ截圖20170425103619.png