我想在活動中實現自定義操作欄。我在下面這樣做了,但是讓我的自定義操作欄與另一個重疊。我附上了下面的屏幕截圖。自定義操作欄重疊其他元素
public class MainActivity extends ActionBarActivity {
private TextView actionBarTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getSupportActionBar();
View customView=getLayoutInflater().inflate(R.layout.actionbar_layout, null);
actionBar.setCustomView(customView);
actionBarTitle =(TextView)findViewById(R.id.actionbar_text);
actionBarTitle.setText("Action bar");
}
}
清單:
<application
android:name="MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme"
android:requiredForAllUsers="false">
<activity android:name="MainActivity"
android:screenOrientation="portrait"/>
</application>
actionbar_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical" >
<ImageView
android:id="@+id/actionbar_icon"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/actionbar_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_toRightOf="@+id/actionbar_icon"
android:text="title" />
</RelativeLayout>
的strings.xml:
<resources>
<string name="app_name">sample</string>
</resources>
styles.xml
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="Dialog_No_Border">
<item name="android:windowIsFloating">true</item>
<item name="android:windowBackground">@color/transparent_color</item>
</style>
</resources>
如何刪除示例文本和黑色背景以便僅顯示自定義視圖?
如何刪除示例文本和黑色背景..只顯示自定義視圖.. – user1862322
(示例)文本和黑色的顏色欄必須消除和唯一的圖標和操作欄文本..... – user1862322