一、在 xml 界面
插入一张拨打电话的图片
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/ic_launcher"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="169dp"
tools:layout_editor_absoluteY="226dp" />
二、java 界面
为图片绑定点击事件。
public class MainActivity extends AppCompatActivity {
ImageView img;
String num = "15258817074";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = findViewById(R.id.imageView2);
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+num));
startActivity(intent);
}
});