穴居。和Cavebabes。 我正在尝试编写一个简单的应用程序来拨打已保存的号码。下面是代码,XML和清单文件。代码编译但是当我尝试在我的手机上运行它,运行Marshmallow时,UI显示正常,但是当我按下按钮时没有任何反应。我究竟做错了什么?万分感谢
pos <- c(4,5,5,6,4,6,4,5.5,6,8,7)
neg <- c(-8,-7,-7,-7,-6,-7,-5,-6,-6.5,-9,-7)
net <- pos+neg
plot.par <- par(mfrow=c(1,1))
par(mar=c(4,4.5,2,1))
plot(pos, type="n", main="", cex.main=1.1, xlab="",
ylab="", cex.lab=1.3, yaxt= "n", xaxt="n", ylim=c(-10, 10))
abline(h=c(-10,-8,-6,-4,-2,0,2,4,6,8,10),col = grey(0.6), lty=3)
abline(v=c(1,4,7),
col = grey(0.6), lty=3)
par(new=T)
barplot(pos, main="", cex.main=1.1, xlab="", col="darkolivegreen", border="darkolivegreen",
ylab="", cex.lab=1.1, yaxt= "n", xaxt="n", ylim=c(-10, 10))
par(new=T)
barplot(neg, main="", cex.main=1.1, xlab="", col="darkgoldenrod3",border="darkgoldenrod3",
ylab="", cex.lab=1.1, yaxt= "n", xaxt="n", ylim=c(-10, 10))
par(new=T)
lines(net, col="firebrick4", lwd = 4)
XML ---------------------------------------------- ------
package com.example.malcolmshingirai.mycall;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button mCall;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mCall = (Button) findViewById(R.id.button2);
mCall.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel: 0123456789"));
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(callIntent);
}
});
}
}
清单权限--------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.malcolmshingirai.mycall.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/textView"
app:layout_constraintVertical_bias="0.502" />
<Button
android:id="@+id/button2"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:text="@string/call_button"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="8dp"
android:layout_marginStart="8dp"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</android.support.constraint.ConstraintLayout>
再次,一千谢谢。