实现按钮跳转&下划线等

按钮点击跳转页面:(在java文件里写)

 

复制代码
 1 public class MainActivity extends AppCompatActivity {
 2 
 3     private Button mbtnTextView;
 4 
 5     @Override
 6     protected void onCreate(Bundle savedInstanceState) {
 7         super.onCreate(savedInstanceState);
 8         setContentView(R.layout.activity_main);
 9 
10         mbtnTextView = findViewById(R.id.btn_textview);
11         mbtnTextView.setOnClickListener(new View.OnClickListener() {
12             @Override
13             public void onClick(View view) {
14                 //跳转到textview演示界面
15                 Intent intent=new Intent(MainActivity.this,TextViewActivity.class);
16                 startActivity(intent);
17             }
18         });
19     }
20 }
复制代码

 

 

页面写不下的话用...表示

复制代码
<TextView
        android:id="@+id/tv_2"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:text="ahsdjahdjashdjsdjsjd"
        android:ellipsize="end"
        android:textColor="#000000"
        android:textSize="25sp"
        android:layout_marginTop="30dp"/>
复制代码

 

插入图标等:

复制代码
<TextView
        android:id="@+id/tv_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="筛选"
        android:drawableRight="@drawable/jiantou"
        android:drawablePadding="30dp"
        android:textColor="#000000"
        android:textSize="25sp" />
复制代码

 

 

中划线和下划线除了页面之外要在Java文件里写:

复制代码
复制代码
 1 public class TextViewActivity extends AppCompatActivity {
 2 
 3     private TextView vvv,mmm,ttt;
 4     @Override
 5     protected void onCreate(Bundle savedInstanceState) {
 6         super.onCreate(savedInstanceState);
 7         setContentView(R.layout.activity_text_view);
 8         vvv=findViewById(R.id.tv_4);//这个命名随便命名,可以不是vvv
 9         vvv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//中划线
10         vvv.getPaint().setAntiAlias(true);//消除锯齿
11 
12         mmm=findViewById(R.id.tv_5);
13         mmm.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
14 
15         ttt=findViewById(R.id.tv_6);
16         ttt.setText(Html.fromHtml("<u>另一种下划线方式</u>"));//页内text内容可以不用写
17     }
18 }
复制代码

 

复制代码

 

跑马灯效果:

复制代码
 1 <TextView
 2         android:id="@+id/tv_7"
 3         android:layout_width="wrap_content"
 4         android:layout_height="wrap_content"
 5         android:text="正在奔跑中啦啦啦啦正在奔跑中啦啦啦啦正在奔跑中啦啦啦啦"
 6         android:textColor="#000000"
 7         android:textSize="25sp"
 8         android:singleLine="true"
 9         android:ellipsize="marquee"
10         android:marqueeRepeatLimit="marquee_forever"//表示永远循环
11         android:focusable="true"//焦点
12         android:focusableInTouchMode="true"/>
复制代码

这个跑马灯效果就是不断滚动的效果,如果不动的话可能是因为文字有点少 ,多复制点就好了,基本上应该是不需要在Java文件中写,只有中划线、下划线需要在Java文件中写代码。

 

posted @   KongLong_cm  阅读(77)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示