當前位置:首頁 » 安卓系統 » 安卓自定義布局背景如何繼承

安卓自定義布局背景如何繼承

發布時間: 2022-01-08 05:36:43

❶ android設置linearlayout布局的背景顏色,怎麼動態改變背景顏色

1、開始打開Android IDE,這里以常用的Android Studio軟體的3.2版本為例,然後可以新建一個工程項目,也可以使用當前已經存在的工程,點擊後等待整個項目載入完畢再進行後續的操作。

❷ android自定義adapter如何改變指定位置上的指定控制項的背景例如我現在想改變第二個It

這個用adapter改變肯定是要加判斷條件的,假如你要改第二個,那你就判定當position=1的時候,修改背景,其他不做處理

安卓手機自定義背景怎麼弄的

你好。友友,點擊頭像中的名片背景處有個相冊選取或拍攝照片。祝愉快。望採納。謝謝

❹ android自定義組件 MyView,怎樣設定它的背景資源(MyView繼承View)

在layout布局文件中設置,或者你可以findByID把控制項找出來,然後用代碼設置屬性。

❺ android怎麼實現自定義對話框的背景

我知道你出現什麼問題了,你是不是寫了一個類繼承了Dialog,然後再實例化,這個dialog,但是button按鈕美發添加監聽器是不? 如果你要是自己繼承了DIalog的話,那麼我們看看源碼把! Dialog implements DialogInterface 也就是說Dialog繼承了 DialogInterface這個介面 好的 我們再看看DialogInterface這個介面把 我們會發現DialogInterface 有一個方法: public static interface OnClickListener { public abstract void onClick(DialogInterface dialoginterface, int i); } 好的 那麼也就是如果我們繼承了Dialog的話,我們同樣也繼承了DialogInterface這個介面的ONclickListner方法所以我們再給button設置onclicklistner的時候就會出錯,因為本身就是不同包的東西,現在放到一個類裡面肯定就會出錯! 解決方法:在給button 設置點擊事件的時候,加上完整的包名就行了! 專門給你敲了個例子你看看: Activity裡面: public class QuestionActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { Dialog ad = new MyDialog(this); ad.show(); return super.onKeyDown(keyCode, event); } } 自定義Dialog裡面: public class MyDialog extends Dialog { Context context; public MyDialog(Context context) { super(context); this.context = context; init(); } public void init() { LinearLayout ll = new LinearLayout(context); ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); Button btn = new Button(context); btn.setText("hello"); /************************************************************/ btn.setOnClickListener(new android.view.View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(context, "hello", 0).show(); MyDialog.this.dismiss(); } }); /**********************************************************/ ll.addView(btn); this.setContentView(ll); } } 注意*****行裡面

❻ 安卓界面布局如何改變所有button的背景顏色

可以使用selector來實現Button的特效

main.xml

Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按下或者獲得焦點Button會變不同顏色"
<SPAN style="COLOR: #ff0000">android:textColor="@color/button_text" </SPAN>/>
</LinearLayout>
www.2cto.com
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按下或者獲得焦點Button會變不同顏色"
android:textColor="@color/button_text" />
</LinearLayout>

XML 文件保存在res/color/button_text.xml

Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="#ffff0000"/> <!-- pressed -->
<item android:state_focused="true" android:color="#ff0000ff"/> <!-- focused -->
<item android:color="#ff000000"/> <!-- default -->
</selector>

背景選擇器-selector

概述
在drawable/xxx.xml中配置,通過配置selector,可以使系統運行時根據控制項對象的狀態使用相應的圖片、文字等。
selector中的常用屬性
android:state_selected 控制項選中狀態,可以為true或false
android:state_focused 控制項獲得焦點狀態,可以為true或false
android:state_pressed 控制項點擊狀態,可以為true或false
android:state_enabled 控制項使能狀態,可以為true或false
android:state_checkable 控制項可勾選狀態,可以為true或false
android:state_checked 控制項勾選狀態,可以為true或false
注意:在狀態描述中,第一個匹配當前狀態的item會被使用。因此,如果第一個item沒有任何狀態特性的話,那麼它將每次都被使用,所以默認的值必須總是在最後。
android:window_focused 應用程序窗口焦點狀態,可以為true或false
android:color 定義特定狀態的顏色
#rgb
#argb
#rrggbb
#aarrggbb
為16進制顏色。這個顏色由rgb值指定,可帶alpha,必須以」#「開頭,後面跟隨alpha-red-green-blue信息,格式可以為:
使用selector設置背景
把下面的XML保存成.xml文件(比如list_item_bg.xml),運行時系統會根據ListView中列表項的狀態來使用相應的背景圖片。
drawable/list_item_bg.xml
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 默認時的背景圖片 -->
<item android:drawable="@drawable/pic1" />

<!-- 沒有焦點時的背景圖片 -->
<item android:state_window_focused="false"
android:drawable="@drawable/pic1" />

<!-- 非觸摸模式下獲得焦點並單擊時的背景圖片 -->
<item android:state_focused="true" android:state_pressed="true"
android:drawable= "@drawable/pic2" />

<!-- 觸摸模式下單擊時的背景圖片 -->
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/pic3" />

<!--選中時的圖片背景 -->
<item android:state_selected="true"
android:drawable="@drawable/pic4" />

<!--獲得焦點時的圖片背景 -->
<item android:state_focused="true"
android:drawable="@drawable/pic5" />
</selector>

使用方法
第一種是在listview中配置android:listSelector=」@drawable/list_item_bg」
第二種是在listview的item中添加屬性android:background=」@drawable/list_item_bg」
第三種是java代碼中使用:
Drawable drawable = getResources().getDrawable(R.drawable.list_item_bg);
listview.setSelector(drawable);

註:列表有時候為黑的情況,需要加上下面的代碼使其透明:
android:cacheColorHint="@android:color/transparent"

使用selector設置字體顏色
drawable/button_font.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="#FF0000" />
<item android:state_focused="true" android:color="#00FF00" />
<item android:state_pressed="true" android:color="#0000FF" />
<item android:color="#000000" />
</selector>

使用方法
android:textColor="@drawable/button_color"

更復雜的效果
還可以實現更復雜的效果,例如漸變等等。 drawable/button_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<!-- 定義當button 處於pressed 狀態時的形態。-->
<shape>
<gradient android:startColor="#8600ff" />
<stroke android:width="2dp"
android:color="#000000" />
<corners android:radius="5dp" />
<padding android:left="10dp"
android:top="10dp"
android:bottom="10dp"
android:right="10dp"/>
</shape>
</item>
<item android:state_focused="true">
<!-- 定義當button獲得 focus時的形態 -->
<shape>
<gradient android:startColor="#eac100"/>
<stroke android:width="2dp"
android:color="#333333"
color="#ffffff"/>
<corners android:radius="8dp" />
<padding android:left="10dp"
android:top="10dp"
android:bottom="10dp"
android:right="10dp"/>
</shape>
</item>
</selector>

使用方法
android:background="@drawable/button_color"
android:focusable="true"

❼ 如何自定義android界面的背景圖片

設置background就行了

❽ 安卓開發android studio中怎樣自定義actionbar的布局

1theme是用於application或activity的。首先打開AndroidManifest文件查看,一般application節點都有默認主題,

2接下來打開上圖中theme所在的文件。res-->values-->styles。

3打開後。可以看到,name屬性正是步驟一中theme的值。在可以看到parent屬性的值,parent是用於繼承內置樣式的。我們接下來要在該樣式的基礎上修改。

4修改action bar的背景。可以從圖中看到,都是一個引用另一個。圖中黃色高亮的部分,是為了兼容性,可以看到其實值是相同的。在這個例子中,因為theme的parent是Theme.AppCompat.Light.DarkActionBar真正起作用的是不帶『android:』前綴的語句,是為了支持低版本的兼容包。而帶前綴的語句是API 11以上支持的。

5修改布局背景。這個在layout文件中也可以改,不過在application的theme中修改可以應用於所有activity。

❾ 求大神指點,,,Android中 如何將標簽的背景顏色設置一下是繼承TabActivity的

看來你不應該設置tabwidget的屬性,而是要設置tabwidget上的組件的屬性,檢查一下那是什麼組件,是panel ? 是圖片?查看你的源碼應該就很清楚了。

❿ android編寫中如何將系統背景換成自己自定義的背景圖片 自己覺得系統黑色背景不好看,想換圖片

在<style></style>標簽中間加上如下的item:<item name="android:backg">@drawable/圖片名</item> ,然後在按鈕監聽事件里用Activity名.this.setTheme(@style/對應的style name);調用就行了。

熱點內容
linux命令全稱 發布:2024-05-17 12:07:54 瀏覽:109
ftpnas區別 發布:2024-05-17 12:06:18 瀏覽:948
512g存儲晶元價格 發布:2024-05-17 12:04:48 瀏覽:962
腳本運行周期 發布:2024-05-17 11:39:09 瀏覽:808
阿里雲伺服器怎麼配置發信功能 發布:2024-05-17 11:37:24 瀏覽:312
編程中的變數 發布:2024-05-17 11:33:06 瀏覽:777
加密視頻怎麼解密 發布:2024-05-17 11:02:52 瀏覽:571
柳工挖機密碼多少合適 發布:2024-05-17 11:00:40 瀏覽:188
android工程嘆號 發布:2024-05-17 10:56:21 瀏覽:481
在蘋果手機應用怎麼比安卓貴 發布:2024-05-17 10:56:20 瀏覽:548