Ari*_*MAZ 0 java android android-layout android-titlebar
我想在标题栏上添加一个按钮,但我无法成功.我已经阅读了很多关于此的文章,但它们都解释了不适合我的方式.我使用ScrollView使屏幕可滚动.但文章建议我使用线性布局.如何使其可滚动并在标题栏上有一个按钮?
这是我的xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#C0C0C0"
android:id="@+id/sw_layout">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:id="@+id/ln_layout">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft=<"@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
.........................
.........................
.........................
</TableLayout>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
在我的活动中,我有这个代码....
LinearLayout ln = (LinearLayout) getWindow().findViewById(R.id.ln_layout);
Button btn = new Button(this);
btn.setText("Test");
ln.addView(btn);
Run Code Online (Sandbox Code Playgroud)
但这并没有显示任何东西,它不会给我任何错误.请给我一个主意.如何将标题栏添加到标题栏?
制作title.xml并设计你的标题:放置按钮等
在活动上
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
Run Code Online (Sandbox Code Playgroud)
您将使用与主要布局相同的方式访问标题上的元素.使用findviewbyid
避免一些外观问题
<style name="theme">
<item name="android:windowTitleBackgroundStyle">@style/themeTitleBackground</item>
<item name="android:windowTitleSize">65dip</item>
</style>
<style name="themeTitleBackground">
<item name="android:layout_height">wrap_content</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在androidmanifest里面
<activity android:theme="@style/theme"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17320 次 |
最近记录: |