我在我的应用程序中使用JakeWharton-Android-ViewPagerIndicator,我还创建了自定义窗口标题。 我试着运行app,我看到自定义标题被活动的其余部分阻挡了一半。
http://postimg.org/image/c5w27rzj7/
这是主要活动代码的一部分:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.layout_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
FragmentPagerAdapter adapter = new TubeFmAdapter(getSupportFragmentManager());
ViewPager pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(adapter);
TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator);
indicator.setViewPager(pager);
initEvents();
}
android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.TubeFM"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/WindowTitleTheme">
<activity
android:name="com.TubeFM.activities.MainActivity"
android:label="TubeFM"
android:screenOrientation="portrait"
android:theme="@style/Theme.PageIndicatorDefaults">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
android:exported="true"/>
</intent-filter>
<meta-data android:name="isLaunchableActivity" android:value="true"/>
</activity>
<activity
android:name="com.TubeFM.activities.VideoPlayerActivity"
android:label="@string/app_name"
android:exported="true"
android:screenOrientation="portrait">
</activity>
<meta-data android:name="isLaunchableActivity" android:value="false"/>
</application>
</manifest>
自定义窗口标题布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:gravity="center_vertical"
android:paddingLeft="10dip"
android:paddingRight="5dip"
>
<ImageView
android:id="@+id/ic_search"
android:src="@drawable/ic_action_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:paddingRight="5dip">
<AutoCompleteTextView
android:id="@+id/editTextSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:background="@drawable/text_search_background"
android:hint="@string/search_artist"
android:imeOptions="actionSearch"
android:inputType="text"
android:visibility="invisible"
android:drawableRight="@drawable/ic_action_search">
</AutoCompleteTextView>
</LinearLayout>
</LinearLayout>
活动主题:
<resources>
<style name="Theme.PageIndicatorDefaults" parent="android:Theme">
<item name="vpiIconPageIndicatorStyle">@style/Widget.IconPageIndicator</item>
<item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item>
</style>
<style name="Widget">
</style>
<style name="Widget.TabPageIndicator" parent="Widget">
<item name="android:gravity">center</item>
<item name="android:background">@drawable/vpi__tab_indicator</item>
<item name="android:paddingLeft">22dip</item>
<item name="android:paddingRight">22dip</item>
<item name="android:paddingTop">12dp</item>
<item name="android:paddingBottom">12dp</item>
<item name="android:textAppearance">@style/TextAppearance.TabPageIndicator
</item>
<item name="android:textSize">11sp</item>
<item name="android:maxLines">1</item>
</style>
<style name="TextAppearance.TabPageIndicator" parent="Widget">
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/vpi__dark_theme</item>
</style>
<style name="Widget.IconPageIndicator" parent="Widget">
<item name="android:layout_marginLeft">6dp</item>
<item name="android:layout_marginRight">6dp</item>
</style>
</resources>
答案 0 :(得分:0)
例如:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="RidesTheme" parent="android:Theme">
<item name="android:windowTitleSize">44dip</item>
<item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
</style>
<style name="WindowTitleBackground">
<item name="android:background">@color/rides_window_title_bg</item>
</style>
<style name="SetRideTheme" parent="android:Theme">
<item name="android:windowTitleSize">56dip</item>
<item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
</style>
</resources>