Ⅰ 如何在android标题栏中添加按钮
Android在标题栏加按钮_网络文库
http://wenku..com/link?url=D93O4XxbjID1hxTF5Y7dhV14mx-aadsaHSSHCSyqzwvr7ug0Rycd-TFy9QVACn91Tzw_
Android中标题栏添加按钮
现在很多的Android程序都在标题栏上都显示了一些按钮和标题,如下图:
下面通过实例来看一下如何实现。
1、在layout下创建一个titlebtn.xml文件,内容如下: [html] view plainprint?
1. <?xml version="1.0" encoding="utf-8"?>
2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andr
oid"
3. android:orientation="horizontal" 4. android:layout_width="fill_parent" 5. android:layout_height="fill_parent"> 6.
7. <ImageButton
8. android:id="@+id/imageButton1" 9. android:layout_width="wrap_content" 10. android:layout_height="wrap_content" 11. android:background="#00000000" 12. android:layout_centerVertical="true" 13. android:layout_alignParentLeft="true" 14. android:src="@drawable/prv" /> 15.
16. <TextView
17. android:layout_width="wrap_content"
Ⅱ android 怎么添加按钮
需要在资源文件中添加一个button,然后如果你需要给这个button增加点击事件,那你就需要在代码中找到这个button,给它添加点击事件监听,在监听中响应你所需要的完成的操作。
Ⅲ Android Studio中自定义标题栏的添加问题
mainifests中设置:
android:theme="@style/AppTheme"(即默认设置).
⒉values->styles.xml中设置:
style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar".
二values->styles.xml中:
在当先使用的style的parent属性添加NoActionBar.如原先为
style name="AppTheme" parent="Theme.AppCompat.Light".
Ⅳ android开发中如何自定义标题栏
Android程序默认的Activity标题栏只能显示一段文字,而且不能改变它的布局、颜色、标题栏的高度等。如果想要在标题栏加上个图标、button、输入框、进度条、修改标题栏颜色等,只能使用自定义的标题栏。自定义标题栏可以通过在onCreate函数中添加以下代码来实现,需要注意的是代码的顺序必须按照下面的样式,否则将无效。
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.mainactivity); //Activity的布局
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar); //标题栏的布局
虽然上面这样可以在标题栏加入一些控件,但是仍然不能改变标题栏的高度、背景色,要想达到这个目的,只能使用theme(主题)。因此往project里先添加一个style。改变背景色修改android:windowTitleBackgroundStyle的值,改变标题栏高度则修改android:windowTitleSize的值。下面是一个示例:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#</item>
</style>
<style name="activityTitlebar" parent="android:Theme">
<item name="android:windowTitleSize">32dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
接着再修改AndroidManifest.xml文件,找到要自定义标题栏的Activity,添加上android:theme值,比如:
java代码
<activity android:name=".MainActivity" android:theme="@style/activityTitlebar">
<activity android:name=".MainActivity" android:theme="@style/activityTitlebar">
android:theme值就是上面那个style.xml文件里定义的一个style的name值。
按照以上的步骤,修改标题栏布局、高度、背景色的功能就实现了。
Ⅳ 怎样在android中添加按钮并设置大小
可通过在布局文件中添加Button标签,通过android:layout_width,android:layout_height属性来设置大小;也可以通过在java代码中直接创建
Button button = new Button(context);
通过setWidth、setHeight方法设置大小,然后通过调用父控件的addView方法添加进视图中。