我需要设置文本从右到左移动或滚动文本,即如何在android中的CustomActionBar主题上使用选框效果。显示我可以做同样的更改。我一直在附加java和xml以及样式文件。需要帮助
我该如何使用它?
**style.xml**
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
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="CustomActionBarTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#F05B30</item>
</style>
<style name="fontForNotificationLandingPage">
<item name="android:fontFamily">NotoSerif-Regular</item>
</style>
</resources>
**New_details.java**
package com.example.ourvadodara;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;
import static com.example.ourvadodara.News.KEY_TITLE;
import static com.example.ourvadodara.News.KEY_Details;
import static com.example.ourvadodara.News.KEY_THUMB_URL;
public class News_details extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_news_details);
getActionBar().setDisplayHomeAsUpEnabled(true);
// Bitmap bitmap = (Bitmap)
// getIntent().getParcelableExtra(KEY_THUMB_URL);
// Bitmap bMapScaled = Bitmap.createScaledBitmap(bitmap,350, 150, true);
String title = "";
String details = "";
String path = "";
Intent intent = getIntent();
if (null != intent) {
title = intent.getStringExtra(KEY_TITLE);
details = intent.getStringExtra(KEY_Details);
path = intent.getStringExtra("img_url");
}
imageLoader il = new imageLoader(this);
il.DisplayImage(path, (ImageView) findViewById(R.id.imgdetails));
Log.i("bitmap", "null");
TextView headlineTxt = (TextView) findViewById(R.id.headlines);
headlineTxt.setText(title);
getActionBar().setTitle(title);
TextView descriptionTxt = (TextView) findViewById(R.id.description);
descriptionTxt.setText(details);
}
}
**activity_news_details.xml**
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#E6E6E6" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#E6E6E6" >
<ImageView
android:id="@+id/imgdetails"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="23dp"
/>
<TextView
android:id="@+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/headlines"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:background="@drawable/rounded_corner"
android:padding="10dp"
android:scrollbars="horizontal" />
<TextView
android:id="@+id/headlines"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imgdetails"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:background="@drawable/rounded_corner"
android:padding="10dp"
android:textAlignment="gravity"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="23sp"
android:textStyle="bold"
android:ellipsize="marquee"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true" />
</RelativeLayout>
</ScrollView>
答案 0 :(得分:0)
试试这个
// make the title scroll!
// find the title TextView
TextView title = (TextView) findViewById(android.R.id.title);
// set the ellipsize mode to MARQUEE and make it scroll only once
title.setEllipsize(TruncateAt.MARQUEE);
title.setMarqueeRepeatLimit(1);
// in order to start strolling, it has to be focusable and focused
title.setFocusable(true);
title.setFocusableInTouchMode(true);
title.requestFocus();