欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

安卓布局java代碼 java寫安卓布局

安卓中的java代碼報(bào)錯(cuò)求助 求大神

你可以使用以下代碼代替你的 ACTION_CALL(推薦):

創(chuàng)新互聯(lián)是一家專業(yè)提供西盟企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站制作、網(wǎng)站建設(shè)、H5響應(yīng)式網(wǎng)站、小程序制作等業(yè)務(wù)。10年已為西盟眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進(jìn)行中。

Intent?intent?=?new?Intent(Intent.ACTION_DIAL);

也可以參考這里,在 manifest?中添加

android.permission.PHONE_CALL

的權(quán)限,并且在撥打電話之前檢驗(yàn)權(quán)限:

//檢查是否已經(jīng)給了權(quán)限

int?checkpermission=?ContextCompat.checkSelfPermission(getApplicationContext(),Manifest.permission.ACCESS_FINE_LOCATION);

if(checkpermission!=PackageManager.PERMISSION_GRANTED){?//沒有給權(quán)限,申請(qǐng)

//參數(shù)分別是當(dāng)前活動(dòng),權(quán)限字符串?dāng)?shù)組,requestcode

ActivityCompat.requestPermissions(MainActivity.this,new?String[]{Manifest.permission.ACCESS_FINE_LOCATION},?1);

//?暫時(shí)使用?DIAL?代替?CALL

Intent?intent?=?new?Intent(Intent.PHONE_DIAL);

intent.setData(Uri.parse("tel:"+number));

startActivity(intent);

}?else?{

//?直接使用?CALL

Intent?intent?=?new?Intent(Intent.PHONE_CALL);

intent.setData(Uri.parse("tel:"+number));

startActivity(intent);

}

然后添加一個(gè)方法:

@Override

public?void?onRequestPermissionsResult(int?requestCode,?@NonNull?String[]?permissions,?@NonNull?int[]?grantResults)?{

super.onRequestPermissionsResult(requestCode,?permissions,?grantResults);

//grantResults數(shù)組與權(quán)限字符串?dāng)?shù)組對(duì)應(yīng),里面存放權(quán)限申請(qǐng)結(jié)果

if(grantResults[0]==?PackageManager.PERMISSION_GRANTED){

//?放已授權(quán)的處理方法

}else{

//?放拒絕授權(quán)的處理方法

Toast.makeText(MainActivity.this,"拒絕授權(quán)",Toast.LENGTH_SHORT).show();

}

}

參考:CSDN

android 如何利用java代碼 在一個(gè)xml布局中插入另一個(gè)xml布局

Android在xml文件中可使用include包含其他定義好的布局, 可以將多處用到的布局單獨(dú)出來,然后用include包含進(jìn)來,這種包含方法相當(dāng)于把原來布局的一部分代碼獨(dú)立出來,供大家共同使用,也就相當(dāng)于面向?qū)ο蛑械念惖母拍畈畈欢?。下面我們逐步講解include的作用。

先看下我們要實(shí)現(xiàn)的整體界面:

一、未使用Include時(shí)

通常情況下,我們直接就能寫出布局代碼,下面是所使用的XML代碼:

[html]?view plaincopy

?xml?version="1.0"?encoding="utf-8"?

LinearLayout?xmlns:android=""????

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical"?

!--?第一部分?--

TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="#ff0000"

android:text="第一個(gè)BTN"?/

Button

android:id="@+id/mybutton"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="?One?Button?"?/

!--?第二部分?--

TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="#00ff00"

android:text="第二個(gè)BTN"?/

Button

android:id="@+id/mybutton"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="?Second?Button?"?/

!--?最后的按鈕?--

Button

android:id="@+id/another"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="?Another?Button?"?/

/LinearLayout

這段代碼理解起來一點(diǎn)難度沒有,就是幾個(gè)TextView和幾個(gè)Button,下面我們用include把這段代碼給分割成幾個(gè)文件,并完成相同的效果;

二、使用Include時(shí)

1、先將上面代碼標(biāo)記有“第一部分”的,代碼段分離成一個(gè)文件(sublayout1.xml);

[html]?view plaincopy

?xml?version="1.0"?encoding="utf-8"?

LinearLayout?xmlns:android=""????

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="#505050"

android:orientation="vertical"?

TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="#ff0000"

android:text="第一個(gè)BTN"?/

Button

android:id="@+id/mybutton"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="?One?Button?"?/

/LinearLayout

2、再將標(biāo)記有“第二部分”的代碼段,分離成第二個(gè)文件(sublayout2.xml):

[html]?view plaincopy

?xml?version="1.0"?encoding="utf-8"?

LinearLayout?xmlns:android=""??

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical"?

TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="#00ff00"

android:text="第二個(gè)BTN"?/

Button

android:id="@+id/mybutton"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="?Second?Button?"?/

/LinearLayout

3、主文件中使用include,將上面兩個(gè)文件包含進(jìn)去(activity_main.xml);

[html]?view plaincopy

?xml?version="1.0"?encoding="utf-8"?

LinearLayout?xmlns:android=""????

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical"?

include

android:id="@+id/main1"

layout="@layout/sublayout1"?/

include

android:id="@+id/main2"

layout="@layout/sublayout2"?/

Button

android:id="@+id/another"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="?Another?Button?"?/

/LinearLayout

這樣就實(shí)現(xiàn)了相同的效果,這里可以看到,include并沒有其它的功能,只是把一個(gè)XML布局引入進(jìn)來當(dāng)做自己的布局,跟直接把引用的這段代碼寫在include處的效果是一樣的。

android 在activity里用java代碼寫Xml布局文件

你是想在activity的代碼里寫linearlayout么?

1、你可以在代碼里面創(chuàng)建一個(gè)LinearLayout (比如 lineLayout1 ),然后針對(duì)這個(gè)變量進(jìn)行設(shè)置

2、然后你需要通過findViewById()的方法,去查找xml定義好的那個(gè)ScrollView,把他放入一個(gè)變量中,如view1,當(dāng)然前提是你要再xml里面給這個(gè)ScrollView起一個(gè)名字

3、調(diào)用view1.add(lineLayout1)方法把lineLayout1加進(jìn)去

當(dāng)然這是一個(gè)大方向,具體的代碼細(xì)節(jié)你要再研究一下

Android Studio如果在java中編寫布局,代碼放在哪個(gè)文件中?什么位置?

1.使用代碼編寫一個(gè)底部選項(xiàng)卡的布局

2.整個(gè)頁面的容器布局(包含F(xiàn)argment,分割線,選項(xiàng)卡)

private void initView(Context context) {

setBackgroundColor(0xfff6f6f6);

FrameLayout frameLayout=new FrameLayout(context);//選項(xiàng)界面容器

frameLayout.setId(FL_ID);

View lineView=new View(context);//分割線

lineView.setId(LINE_ID);

RelativeLayout.LayoutParams rlParams=new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

rlParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);

rlParams.addRule(RelativeLayout.ABOVE , LINE_ID);

lineView.setBackgroundColor(lineColor);

RelativeLayout.LayoutParams rlParams2=new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, DensityUtils.dip2px(context, 1));

rlParams2.addRule(RelativeLayout.ABOVE , TAB_ID);

addView(frameLayout, rlParams);//選項(xiàng)界面容器

addView(lineView,rlParams2);//分割線

//選項(xiàng)卡容器

linearLayout=new LinearLayout(context);

linearLayout.setBackgroundColor(tabBgColor);

linearLayout.setOrientation(LinearLayout.HORIZONTAL);

linearLayout.setGravity(Gravity.CENTER_VERTICAL);

linearLayout.setId(TAB_ID);

tabNum=tabIcos.length;

for (int i = 0; i tabNum; i++) {

View view = createIndicator(tabIcos[i], tabtxts[i], tabItemTvColor, "itemTag"+i, "icoTag" + i, "txtTag" + i);

view.setOnClickListener(OnClick);

if(i== nowTabIndex){//初始化選項(xiàng)卡

changeTab(view, i);

}

linearLay

當(dāng)前題目:安卓布局java代碼 java寫安卓布局
轉(zhuǎn)載注明:http://chinadenli.net/article10/dogshgo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站設(shè)計(jì)、動(dòng)態(tài)網(wǎng)站微信公眾號(hào)、定制開發(fā)響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計(jì)公司